Reputation: 6133
I'm hoping somebody can help me solve a syntax problem with a TSQL xpath query.
Given the following xml:
<emails>
<email></email>
<email></email>
</emails>
I'm trying to execute the following query:
select * from messages where SendTo.value('(/emails/email)[1]', 'nvarchar(max)') like '%[email value]%'
My query looks only in the first email element and it needs to look in all email elements.
Thanks, Chris
Upvotes: 0
Views: 1229
Reputation: 12281
Try this :-
select * from messages
CROSS APPLY SendTo.nodes('/emails/email') AS Artists(a)
where a.value('(text())[1]', 'nvarchar(max)') like '%[email value]%'
Demo in SQL FIDDLE
Upvotes: 1