I use the WITH XMLNAMESPACES statement in SQL Server 2008 to define some namespaces in the form of
;WITH XMLNAMESPACES ('http://bla' AS nsBlub)
And then I would like to execute multiple(!) select statements all making use of the above defined nsBlub namespace.
But only the first select statement under the above WITH XMLNAMESPACES statement benefits from the namespace declaration, so I need to write the same WITH XMLNAMESPACES statement before every select statement at the moment…
What am I missing – how do I define a namespace with WITH XMLNAMESPACES “globally”?
Thanks all!
You cannot do that, unfortunately.
The
WITH XMLNAMESPACESclause is good for one statement only. It’s almost like a “header” attribute for your next statement – you cannot extend that over more than one statement.For the next one, you have to repeat the
WITH XMLNAMESPACESagain.There’s no workaround for this, as far as I know.