MSSQLString FunctionsSTRING_AGG
FORMAT

STRING_AGGString Functions

STRING_SPLIT

Aggregates strings with a separator.

Syntax

STRING_AGG(expr, sep) [WITHIN GROUP (ORDER BY ...)]

Example

Enter values below to update the example in real time.

department_id
last_name
members
employees
-- 부서별 직원 목록
SELECT department_id,
       STRING_AGG(last_name, ', ') WITHIN GROUP (ORDER BY last_name) AS members
FROM employees
GROUP BY department_id;