Skip to content

Instantly share code, notes, and snippets.

@shaisachs
Last active May 1, 2018 18:53
Show Gist options
  • Save shaisachs/d6c04a715d6eb2aa8aa56bb01a6b65c9 to your computer and use it in GitHub Desktop.
Save shaisachs/d6c04a715d6eb2aa8aa56bb01a6b65c9 to your computer and use it in GitHub Desktop.
TSQL rows to csv
-- from https://stackoverflow.com/questions/887628/convert-multiple-rows-into-one-with-comma-as-separator
select *
into #tmpdata
from things
where thingid >= 100 and thingid <= 200
declare @answer varchar(1000) = ''
select @answer = @answer + id + ', ' from #tmpdata
select @answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment