tsql join multiple record in one string code example
Example 1: tsql join multiple record in one string
Select CountryName from Application.Countries
Declare @val Varchar(MAX);
Select @val = COALESCE(@val + ', ' + CountryName, CountryName)
From Application.Countries Select @val;
Example 2: tsql join multiple record in one string
-- Concatenates results into one single varchar with separator
SELECT LISTAGG(column_name, ',') WITHIN GROUP (ORDER BY column_name)
FROM YOUR_TABLE;