En SQL Server anterior a 2017, puede hacer:
select stuff( (select ',' + cast(t.id as varchar(max))
from tabel t
for xml path ('')
), 1, 1, ''
);
El único propósito de stuff()
es eliminar la coma inicial. El trabajo lo está haciendo for xml path
.