Wednesday, October 5, 2011

Reading XML Attribute, directly in SQL.

DECLARE @statXML xml;

SET @statXML =
 N'<statistics>

   <element code="P10" type="   range" />
   <element code="P25" type="   range" />
   <element code="P50" type="   range" />
   <element code="P75" type="   range" />
   <element code="P90" type="   range" />
 </statistics>
';

SELECT
t.c.value(N'@code', N'nvarchar(10)') AS code,
t.c.value(N'@type', N'nvarchar(10)') AS code
FROM
@statXML.nodes(N'/statistics/element') t(c);

This should give you output as


Code Type




P10    range
P25    range
P50    range
P75    range
P90    range

No comments:

Post a Comment