Skip to content

Instantly share code, notes, and snippets.

@sgissinger
Created January 24, 2019 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgissinger/abe1668726f9b1a139ab1ab69810f550 to your computer and use it in GitHub Desktop.
Save sgissinger/abe1668726f9b1a139ab1ab69810f550 to your computer and use it in GitHub Desktop.
Group by XML PATH
with partitioned_data as
(
select dossier, dos from (
select dossier, ntile(50) over(order by dossier) as dos from [dbo].[input_legacy_excel]
) x
)
Select P.dos, SUBSTRING(STUFF(
(
SELECT ',' + dossier
FROM partitioned_data
where dos = p.dos
FOR XML PATH(''),TYPE).value('(./text())[1]', 'VARCHAR(MAX)'), 1,2,''
), 2, 999999) As dossiers
from partitioned_data p
group by p.dos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment