STRING_AGG function In SQL Server

In this article, we will learn about the concept of the STRING_AGG function in SQL servers.

Overview

  • STRING_AGG function is counted in the aggregation function and introduced in SQL server 2017.
  • STRING_AGG function gathers all expressions from rows and then puts them together in these row’s expressions in order to obtain a string.
  • Additionally, this function takes a separator to separate an expression value to be concatenated.

Syntax

STRING_AGG ( expression, separator )

How it works

STRING_AGG function takes all the expressions and separates them by a given separator.

Example

In the above image, there is a number of technology displays in column 2. And now we will concatenate in one string and separate each row value by coma(,).

SELECT STRING_AGG(Name,', ') As Result FROM Department

Output

I hope you guys found something useful.

Thank you.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories