Stuff example

0

Please login or register to vote for this query.

(click on this box to dismiss)

Open Source Meta

Q&A about the site for people organizing, marketing or licensing open source development projects

CREATE TABLE #Temp
(
	[Code] VARCHAR(2),
	[Message] VARCHAR(10)
)

INSERT INTO #Temp
(
	[Code],
	[Message]
)
SELECT 'AA', 'neat' UNION
SELECT 'AA', 'great' UNION
SELECT 'BB', 'exciting' UNION
SELECT 'BB', 'dull' UNION
SELECT 'BB', 'neat' UNION
SELECT 'CC', 'great'

SELECT
	[Code],
	STUFF(
		(
			SELECT
				',' + i.[Message]
			FROM
				#Temp AS i
			WHERE
				i.[Code] = o.[Code]
			FOR XML PATH('')
		), 1, 1, '') AS [Messages]
FROM
	#Temp AS o
GROUP BY
	[Code]

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results