I’m working with an API that returns property information. Some of the textual information is stored across child nodes and I’d like to concatenate it into a single string (VARCHAR).
My process is that I obtain the xml through a webservice, then pass this through to a proc which extracts the xml values and inserts them into a view, this is a snippet of the xml that I’m getting back:
<properties>
<property propertyid="1234">
<bullets>
<bullet>nice garden</bullet>
<bullet>it smells a bit</bullet>
<bullet>body under the patio</bullet>
</bullets>
</property>
...
</properties>
This is a glimpse into how the xml is being queried to extract values from it:
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')
In this example, I’d like to be able to extract the information from the xml so it ends up like this:
PropertyId Description
1234 'nice garden\r\nit smells a bit\r\nbody under the patio
Is this going to be possible in pure sql/xml or am I going to need to perform some pre-processing on the xml before I enter SQL land?
Any help greatly appreciated (as always).
Does this work for you?