Skip to content

Instantly share code, notes, and snippets.

@oscarandreu
Last active February 5, 2016 14:13
Show Gist options
  • Select an option

  • Save oscarandreu/950777882df806cc2b54 to your computer and use it in GitHub Desktop.

Select an option

Save oscarandreu/950777882df806cc2b54 to your computer and use it in GitHub Desktop.
SQL use xml input parameters
DECLARE @XML AS XML
SET @XML = '<root>
<row><Id>1855</Id><Count>2</Count></row>
<row><Id>1856</Id><Count>4</Count></row>
<row><Id>1857</Id><Count>1</Count></row>
</root>'
;WITH CTE AS
(
SELECT
Id = XTbl.value('(Id)[1]', 'varchar(50)'),
[Count] = XTbl.value('(Count)[1]', 'varchar(50)')
FROM
@XML.nodes('/root/row') AS XD(XTbl)
)
select * from CTE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment