Hi everyoneI have a table with XML. And i want to query it by @id variable.CREATE Table test(Filter XML)insert into testselect '<root> <book> <id>1</id> <name>SQLSERVER</name> <authors> <string>John</string> <string>Michael</string> <string>Jane</string> </authors> </book> <book> <id>2</id> <name>SSAnalysisServer</name> <authors> <string>Abraham</string> <string>Suzan</string> </authors> </book></root>'
I can easily query table like below. DECLARE @resultXML xml select @resultXML = nref.query('authors') FROM test CROSS APPLY Filter.nodes('//root/book') AS R(nref) WHERE nref.exist('id[. = "2"]') = 1 Select @resultXMLBut i have a problem withWHERE nref.exist('id[. = "2"]') = 1
this line.I want to make <<id>> column as variable. @id.declare @id varchar(10)declare @sSQL varchar(1000)set @id='1'set @sSql= 'DECLARE @resultXML xml select @resultXML = nref.query(''authors'') FROM test CROSS APPLY Filter.nodes(''//root/book'') AS R(nref) WHERE nref.exist(''id[. = "@id"]'') = 1'set @sSql = replace(@sSQL,'@id',@id)select @sSqlhow can i get the result of this query???I want result of exec(@sSQL)
Thanks all