Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
SELECT @Name = Name FROM Table FOR XML AUTO
不起作用,如何将 XML 结果从使用中获取FOR XML到变量中?
FOR XML
这将起作用:
SELECT @Name = CONVERT(XML, ( SELECT Name FROM SomeTable FOR XML AUTO ));
您可以在没有包装语句的情况下尝试它,CONVERT(XML, (...))但我发现 SQL Server 不喜欢在没有显式转换的情况下分配给 XML 变量。
CONVERT(XML, (...))