Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

is it possible to use parameter as the XQuery string in xmlColumn.query() method?

172 views
Skip to first unread message

shawn

unread,
Aug 21, 2008, 11:26:04 AM8/21/08
to
Hi guys:

select experience.query(N'/root/experience')
from UsersProperties

the code above works, but I want to use parameter to substitue string
literal '/root/experience', like this

declare @query as nvarchar(200)
set @query = N'/root/experience'

select experience.query(@query)
from UsersProperties

SqlServer gave me an error:
Msg 8172, Level 16, State 1, Line 4
The argument 1 of the xml data type method "query" must be a string literal.


So is there any other approach?

Martin Honnen

unread,
Aug 21, 2008, 11:33:36 AM8/21/08
to

Not really. What you can do is e.g.
declare @n nvarchar(20)
set @n = N'experience'
select experience.query(N'/root/*[local-name() = sql:variable("@n")]')

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

deepak....@gmail.com

unread,
Nov 5, 2012, 7:27:02 AM11/5/12
to Martin...@gmx.de
select t.HotelXml.query('(/Hotel/HotelDetail[HotelCode=("107033","112156")])') from tblFHCacheXml t

i am trying this query for dynamic HotelCode and Getting error while above running fine
0 new messages