Skip to main content

Concatenate strings from column into a single row in Transact SQL.

--
-- Concatenate strings from column into a single row
--

-- Table STATES has at least one row called states including the following
-- information:
-- > USA
-- > Germany
-- > France
-- > Great Britain
--

DECLARE @states VARCHAR(1024)

SELECT
    @states = COALESCE(@states + ',', '') + states
FROM
    states

SELECT @states

--> output: USA,Germany,France,Great Britain