Skip to content

Instantly share code, notes, and snippets.

@jasoncable
Created November 20, 2019 14:04
Show Gist options
  • Save jasoncable/21462a72706c6544a73bc4cdc4c603f6 to your computer and use it in GitHub Desktop.
Save jasoncable/21462a72706c6544a73bc4cdc4c603f6 to your computer and use it in GitHub Desktop.
T-SQL - Comma-seperated list from subselect (one to many)
select d.*,
stuff((select ', ' + f.Name
from FolderItem fi
join Folder f on fi.FolderId = f.FolderId
where d.DocumentId = fi.DocumentId
for xml path('')), 1, 2, '') as folders
from Document d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment