Reputation: 7024
This is a sample query
select *
from tablename
where tableid in (<sub query>);
The <sub query>
here returns null or a string of pattern 'id1','id2','id3'
My <sub query>
is something like:
select xml_data.value('(/Node/SubNode)[1]', 'varchar(max)'))
from tablename
where tableid = '9944169f-95a6-4570-89d7-b57a3fe1b693'
The problem :
My sub query returns proper data ('id1','id2','id3'
) but the parent query considers the complete result as one single string and hence returns 0 rows always.
How can I tell SQL Server not to escape single quotes present in the result of my sub-query?
Upvotes: 1
Views: 142
Reputation: 51514
It's not clear if your subquery is applying to the same table as the first query, but this should show you the general direction
declare @x xml = '<Node><SubNode>t1</SubNode><SubNode>t2</SubNode></Node>'
declare @t table (v varchar(20))
insert @t values ('t1'),('t3')
select table1.*
from
@t table1
inner join
@x.nodes('/Node/SubNode') t(x)
on table1.v = t.x.value('.','varchar(100)')
Upvotes: 2