Make a subquery:
select ( SELECT Names FROM @Test t FOR XML PATH ('Test'),TYPE) as Test
Subqueries produce values, but never provide a name for the column. I also pointed out ,TYPE , because otherwise it will convert to varchar(max) result, whereas you apparently want to save it as xml .
source share