Lets consider following table
CREATE TABLE TEST
(
CityName NVARCHAR(20),
Number INT
)
INSERT INTO TEST VALUES ('New Jork', 100)
INSERT INTO TEST VALUES ('London', 150)
INSERT INTO TEST VALUES ('Paris', 110)
Based on first column I want to get comma-separated values in a string, expected result - "New Jork, London, Paris"
I tried:
SELECT STRING_AGG(CityName, ',') FROM TEST
But instead of comma-separated values in one string; I got output table of size 1x1 with desired values.
I also tried resolution from following question: SQL Server convert select a column and convert it to a string
But it doesn't work on Azure returning error as follows:
A variable that has been assigned in a SELECT statement cannot be included in a expression or assignment when used in conjunction with a from clause.