I am using the FOR XML PATH
function in order to concatenate multiple columns into a single row. However, I can't figure out how to alias the column name of the resulting table.
Here is the SQL query:
SELECT Comment
FROM Comments
WHERE ID = 1006
FOR XML PATH('')
I have tried the following two methods which generate an error message:
SELECT Comment
FROM Comments
WHERE ID = 1006
FOR XML PATH('') [Comment_Agg];
SELECT * AS Comment_Agg
FROM
(SELECT Comment
FROM Comments
WHERE ID = 1006
FOR XML PATH(''));
FYI, I am using SSMS 18.