Comma-Delimited List using Coalesce


/ Published in: SQL
Save to your folder(s)

If you ever need to build a comma delimited list out of a column in SQL you can easily do this using the COALESCE function.


Copy this code and paste it in your HTML
  1. DECLARE @IDlist VARCHAR(100)
  2. SELECT @IDlist = COALESCE(@IDlist + ', ', '') + CAST(id AS VARCHAR(5)) FROM tbl
  3. SELECT @IDlist

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.