Reporting errors
statements #tsql#statements
This article describes guidelines for using the
data type methods.
The
data type methods can’t be used in the
statement as shown in the following
example. The
data type methods are treated as subqueries, and subqueries aren’t allowed
in the
statement. As a result, the following example returns an error:
A solution is to first assign the result of the
method to a variable of
type and then
specify the variable in the query.
The
data type methods are treated internally as subqueries. Because
requires a
scalar and doesn’t allow aggregates and subqueries, you can’t specify the
data type
methods in the
clause. A solution is to call a user-defined function that uses XML
methods inside of it.
node()
value()
nodes()
value()
XACT_ABORT
PRINT
PRINT
GROUP BY
GROUP BY
DECLARE
@x
XML
SET
@x =
'<root>Hello</root>'
PRINT @x.value(
'/root[1]'
,
'varchar(20)'
)
-- will not work because this is treated as a subquery (select top 1 col from table)
DECLARE
@x
XML
DECLARE
@c
VARCHAR (
max
)
SET
@x =
'<root>Hello</root>'
SET
@c = @x.value(
'/root[1]'
,
'VARCHAR(11)'
)
PRINT @c