I am using Visual Studio 2015 and have a problem in my SQL Server database project with STRING_AGG WITHIN GROUP.
SELECT [Continent],
STRING_AGG([Country], ', ') WITHIN GROUP (ORDER BY [Country]) AS CountryList
FROM [Country]
GROUP BY [Continent]
This code gives error SQL46010: Incorrect syntax near AS. Without
WITHIN GROUP (ORDER BY [Country])
no problems.
Destination platform installed on
Microsoft Azure SQL Database V12
The target debug connection is established in the local SQL Server vNext database.
In SQL Server Management Studio, this piece of code runs without any problems. Running the stored procedure in SSMS or from the code gives the expected and correct result (1 line per continent with a list of countries on the continent, separated by commas, sorted by country).
Meanwhile, I installed Visual Studio 2017, hoping this fixes the error, but no luck.
SQL Server 17 data tools installed (build 14.0.61704.140).