Geeks With Blogs
Igor Milovanović .NET, cats and more...

All XML data type methods  (query (), exists(), value() ...) require a constant string as parameter. If you want to pass a T-SQL parameter to  XQuery (e.g. in a stored procedure), you have to use the XQuery functions from the sql: namespace: sql:variable() and sql:column (). Simple enough, but there is a catch: you can't use these function everywhere (e.g. you can't pass the sub tree node to the FWOR statement as a sql parameter).

The workaround is to use the SQL Server exec () function: define the whole statement (including the sql part) as a sql variable (you can use string concatenation) and execute it with exec function. There is an example of this workaround on Mike Rorke´s MSDN Blog.

[1] http://blogs.msdn.com/mrorke/archive/2005/10/24/484237.aspx

Posted on Friday, January 20, 2006 6:00 PM .NET | Back to top


Comments on this post: Create Dynamic XQuery Statements with SQL Server 2005

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Igor Milovanovic | Powered by: GeeksWithBlogs.net