1
DECLARE @XML1 XML

SET @XML1=SELECT XMLCOLUMN FROM TABLE WHERE ID='123-456'

当我这样做时,我收到以下错误消息:

关键字“SELECT”附近的语法不正确。

谁能帮助我如何将 xmlcolumn 值分配给 xml 变量。

4

1 回答 1

2

采用

SELECT @XML1= XMLCOLUMN FROM TABLE WHERE ID='123-456'

或者

SET @XML1= (SELECT XMLCOLUMN FROM TABLE WHERE ID='123-456')

如果查询恰好返回一行,则它们的行为相同,但其他情况不同。

+----+-------------------------------------------------------+------------------------------------------+
|    |                        SELECT                         |                   SET                    |
+----+-------------------------------------------------------+------------------------------------------+
| 0  | No Assignment made. Variable has original value.      | Variable set to null                     |
| 1  | Variable assigned the one matching value              | Variable assigned the one matching value |
| >1 | Variable assigned arbitrary value from matching rows. | Error raised                             |
+----+-------------------------------------------------------+------------------------------------------+
于 2013-01-17T17:10:42.577 回答