let's have an example.
Declare @myXML XML
SET @myXML = N'<rows>
<row Model="toyota" Year="2005" />
<row Model="mazda" Year="2008" />
<row Model="ford" Year="2000" />
</rows>'
SELECT T.Item.value('@Model','varchar(20)') AS Model,
T.Item.value('@Year','varchar(20)') AS Year
FROM @myXML.nodes('/rows[1]/row') AS T(Item)
OR
Declare @myXML XMLSET @myXML = N'<rows>
<row>
<Model>toyota</Model>
<Year>2007</Year>
</row>
<row>
<Model>ford</Model>
<Year>2005</Year>
</row>
</rows>'
SELECT T.Item.query('./Model').value('.', 'VARCHAR(20)') AS Model,
T.Item.query('./Year').value('.', 'VARCHAR(20)') AS Year
FROM @myXML.nodes('/rows[1]/row') AS T(Item)
1 comments:
Really informative blog about Sending multiple values in XML to database from application and parse using XQuery in SQL Server 2005.It never came to my mind that SQL Server 2005's XML support can be used in this way.Thanks for sharing it.
what is a digital signature
Post a Comment