Reputation: 13243
SELECT @Name = Name FROM Table FOR XML AUTO
Does not work, how do you get the XML result from using FOR XML
into a variable?
Upvotes: 1
Views: 84
Reputation: 50855
This will work:
SELECT @Name = CONVERT(XML, (
SELECT Name
FROM SomeTable
FOR XML AUTO
));
You can try it without the wrapping CONVERT(XML, (...))
statement but I've found that SQL Server doesn't like assigning to XML variables without that explicit cast.
Upvotes: 3