It works with both:
WITH q AS
(
SELECT CAST('<root><node>1</node></root>' AS XML) AS doc
)
SELECT doc.value('(/root/node)[1]', 'INT'),
doc.value(N'(/root/node)[1]', 'INT')
FROM q
Note that the XQuery
is compiled during the parsing stage, i. e. you can supply only the string literal as first argument (not a column, expression or a variable).
This string literal has no "type", since type assumes a set of possible values that are known only at runtime, and XML
functions accept only literal XQuery
expressions which should be known at compile time.
You cannot pass them from the arguments or your functions or as variables, you can only hardcode them into the query.
Treat them as reserved words (like SELECT
or UPDATE
), which for some reason should be enclosed into single quotes.
You should build the whole query dynamically if you want the XQuery
to be dynamic.