Last active
February 5, 2016 14:13
-
-
Save oscarandreu/950777882df806cc2b54 to your computer and use it in GitHub Desktop.
SQL use xml input parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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