Created
January 24, 2019 16:07
-
-
Save sgissinger/abe1668726f9b1a139ab1ab69810f550 to your computer and use it in GitHub Desktop.
Group by XML PATH
This file contains hidden or 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
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