Skip to content

Instantly share code, notes, and snippets.

@mjswart
Created August 3, 2017 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjswart/eca87368f5c07e54b2c3243986166dfc to your computer and use it in GitHub Desktop.
Save mjswart/eca87368f5c07e54b2c3243986166dfc to your computer and use it in GitHub Desktop.
xml example
declare @xml xml = N'
<root>
<blat x="abc1">asdf</blat>
<blat x="abc2">asdf</blat>
<blat x="def">asdf</blat>
<blat x="def">asdf</blat>
<blat y="abc">asdf</blat>
</root>';
select nodes.n.query('.')
from @xml.nodes('//blat[(@x)]') nodes(n)
cross apply (select nodes.n.value('(./@x)[1]', 'nvarchar(100)')) as x(val)
where x.val like 'abc%'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment