Created
September 24, 2013 14:41
-
-
Save mjul/6685770 to your computer and use it in GitHub Desktop.
From an XML document in SQL Server, extract the value of an XML node via an XML query.
For example, to extract the TransactionId value as a Guid from the Metadata node on an XML document, do this:
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
<FooHappened> | |
<Metadata xmlns:d2p1="http://schemas.datacontract.org/2004/07/FooSchema"> | |
<d2p1:TransactionId>95a2e035-260b-4806-920b-e584878414e0</d2p1:TransactionId> | |
</Metadata> | |
</FooHappened> |
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
SELECT | |
[Id] | |
,cast([EventData] as xml) | |
.value('(/*/*[local-name() = "Metadata"]/*[local-name() = "TransactionId"])[1]', 'uniqueidentifier') as txid | |
FROM [Playground].[command].[Events] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment