Last active
August 29, 2015 14:21
-
-
Save clintmjohnson/f15a84f48076544dc1fc to your computer and use it in GitHub Desktop.
Convert Vertical Row value to Comma Separated Values Using STUFF SQL SERVER
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @Heroes TABLE ( | |
[HeroName] VARCHAR(20) | |
) | |
INSERT INTO @Heroes ( [HeroName] ) | |
VALUES ( 'Superman' ), ( 'Batman' ), ('Ironman'), ('Wolverine') | |
--SELECT * FROM @Heroes | |
SELECT STUFF((SELECT ',' + [HeroName] | |
FROM @Heroes | |
ORDER BY [HeroName] | |
FOR XML PATH('')), 1, 1, '') AS [Output] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment