37

I've downloaded and installed SQL Server 2016. When I attempted to use the STRING_AGG function I receive this error. Here is my code:

SELECT STRING_AGG(cast(FieldNumber AS VARCHAR(100)), ',') FROM Fields 

I've installed SQL Server 2016 and SP1. Is there anything else I need to do. Here is the feature I am trying to use. String Agg

1
  • 2
    When you need to aggregate lists to strings in pre-"STRING_ADD" SQL Server versions, check out the FOR XML or FOR JSON statements, which can be put on subqueries. They do not provide the exact functionality, put are still powerful tools. Commented Mar 5, 2018 at 6:07

3 Answers 3

56

STRING_AGG is not introduced in SQL SERVER 2016.

It is introduced in SQL SERVER 2017. In the MSDN link you have provided it is mentioned THIS TOPIC APPLIES TO : SQL Server 2017 not SQL SERVER 2016.

At the time of the question, this version was known by the code name "vNext", described as:

SQL Server vNext represents a major step towards making SQL Server a platform that enables choices of development languages, data types, on-premises and in the cloud, and across operating systems by bringing the power of SQL Server to Linux, Linux-based Docker containers, and Windows. SQL Server vNext also includes the features added in SQL Server 2016 service packs

Sign up to request clarification or add additional context in comments.

3 Comments

vNext was only a project name during development. STRING_AGG was made publicly available as of SQL Server 2017.
sigh.........
btw postgres had arrays in 2001
5

Please refer to comma delimited list as a single string, T-SQL. There are instructions how to use STUFF function to construct such a list.

Comments

0

You might have multiple SQL server instances installed for various SQL versions. Go to the Services and start the service for newly installed SQL server version instance.

Then connect that instance with your SQL server management studio.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.