我正在使用返回屬性信息的API。一些文本信息存儲在子節點中,我想將它連接成單個字符串(VARCHAR)。將子節點的文本連接到單個列中
我的過程是,我通過web服務獲取xml,然後將其傳遞給提取xml值並將它們插入到視圖中的proc,這是我返回的xml代碼片段:
<properties>
<property propertyid="1234">
<bullets>
<bullet>nice garden</bullet>
<bullet>it smells a bit</bullet>
<bullet>body under the patio</bullet>
</bullets>
</property>
...
</properties>
這是窺探到XML被查詢如何從中提取值:
INSERT
INTO VProperty
( PropertyId,
Description
)
SELECT P.value('@propertyid', 'INT'),
NULL -- extract all the bullet text values into a single string
FROM @xml.nodes('/properties/property')
在這個例子中,我希望能夠從XML所以它提取信息結果如下:
PropertyId Description
1234 'nice garden\r\nit smells a bit\r\nbody under the patio
這是可能的純sql/xml或我需要在xml執行一些預處理之前,我進入SQL土地?
任何幫助非常感謝(一如既往)。
繁榮。我在尋找解決方案時遇到了類似的情況,但無法完成工作 - 完美地工作,謝謝。 –