Created
August 9, 2011 12:58
-
-
Save fakedarren/1133969 to your computer and use it in GitHub Desktop.
Epic XML SQL Query
This file contains 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 @MyXml XML | |
SET @MyXml = CAST(' | |
<content> | |
<item> | |
<id>1</id> | |
<path>foo</path> | |
</item> | |
<item> | |
<id>2</id> | |
<path>bar</path> | |
</item> | |
<item> | |
<id>3</id> | |
<path>foobar</path> | |
</item> | |
</content> | |
' AS XML) | |
SELECT | |
field.value('(id)[1]','int') as FieldID, | |
field.value('(path)[1]','varchar(500)') as FieldName | |
FROM | |
@MyXml.nodes('//item') as Fields(field) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment