Querying XML Data in SQL Server -
in 1 of table column (nvarchar), data stored in xml format.
in example, data looks :
<datatype id="76" name="disp_dest" hdl="47/4/sb8_3-910-8243-19/0/76" odobjid="385"> <datatypevalue id="1" name="lowpressurerinse" /> <datatypevalue id="0" name="shortinlet" /> </datatype>
i checked few sql server function, need define namespace in order extract values out.
formatted can know field retrieve.
<datatype id="76" name="disp_dest" hdl="47/4/sb8_3-910-8243-19/0/76" odobjid="385"> <datatypevalue id="1" name="lowpressurerinse" /> <datatypevalue id="0" name="shortinlet" /> </datatype>
the expected output be
disp_dest, lowpressurerinse disp_dest, shortinlet
do think achievable using sql server xml related functions ?
thanks.
here 1 way using value
, query
method
declare @xml xml = '<datatype id="76" name="disp_dest" hdl="47/4/sb8_3-910-8243-19/0/76" odobjid="385"> <datatypevalue id="1" name="lowpressurerinse" /> <datatypevalue id="0" name="shortinlet" /> </datatype>' select convert(varchar(1000), @xml.query('data(datatype/@name[1])')), c.value('@name', 'varchar(1000)') @xml.nodes('datatype/datatypevalue') x (c)
Comments
Post a Comment