In this article, we will learn about the concept of the STRING_AGG function in SQL servers.
- 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.
STRING_AGG ( expression, separator )
How it works
STRING_AGG function takes all the expressions and separates them by a given separator.
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
I hope you guys found something useful.