Using a variable as an xpath value in xml.query


i trying use variable xpath when query statement on xml document in sql server 2008. have tried

declare @str varchar(8000)
set @str = 'acord/insurancesvc/persautopolicyaddrq/producer/producerinfo/contractnumber'
select @mydoc.query(@str)

returns

msg 8172, level 16, state 1, line 11
argument 1 of xml data type method "query" must string literal.


, have tried

declare @str varchar(8000)
set @str = 'acord/insurancesvc/persautopolicyaddrq/producer/producerinfo/contractnumber'
select @mydoc.query('sql:variable("@str")')

returns

acord/insurancesvc/persautopolicyaddrq/producer/producerinfo/contractnumber


have ideas on how can it?

thanks!
michael

dynamic sql:
declare @str varchar(8000) set @str = 'select @mydoc.query(''acord/insurancesvc/persautopolicyaddrq/producer/producerinfo/contractnumber'')' exec (@str) 
know, stinks.

rbarryyoung


SQL Server  >  SQL Server XML



Comments

Popular posts from this blog

Conditional formatting a graph vertical axis in SSRS 2012 charts

Register with Power BI failed

SQL server replication error Cannot find the dbo or user defined function........