by
3
6
2,742
1
Top 1% !
Popular
Famous
Easy-to-find
Specified
OpenSource
Popularity: 5744th place
DBMSMS SQL Server
Languagesql
LicenseMIT_X11
OSWindows

How to query some values inside XML in SQL Server

This query relies on 'value' operator applied on XML fields. You can directly transform the resulting value into a particular type with the second parameter of this function.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/228783/How-to-query-some-values-inside-XML-in-S?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
WITH XMLNAMESPACES ('http://www.snip2code.com/namespaces/s2c' AS s2c) SELECT field1, field2 FROM MyTable WHERE MyXMLField.value('/s2c:root/fieldName != ""', 'bit') = 1 WITH XMLNAMESPACES ('http://www.snip2code.com/namespaces/s2c' AS s2c) SELECT field1, field2 FROM MyTable WHERE MyXMLField.value('(/s2c:root/fieldName/text())[1]', 'varchar(100)') = 'some text'
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus