Skip to content

Instantly share code, notes, and snippets.

@sir4ju1
Created April 16, 2014 01:24
Show Gist options
  • Save sir4ju1/10795851 to your computer and use it in GitHub Desktop.
Save sir4ju1/10795851 to your computer and use it in GitHub Desktop.
group_concat equivalent
SELECT
G.GROUP_ID,
G.GROUP_NAME,
stuff(
(
select cast(',' as varchar(max)) + U.USERNAME
from USER_GROUPS U
WHERE U.GROUP_ID = G.GROUP_ID
order by U.USERNAME
for xml path('')
), 1, 1, '') AS USERS
FROM
GROUPS G
ORDER BY
G.GROUP_NAME ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment