Posted By

mcbutterbuns on 05/20/08


Tagged

sql list comma-delimited coalesce


Versions (?)

Comma-Delimited List using Coalesce


 / Published in: SQL
 

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.

  1. DECLARE @IDlist varchar(100)
  2. SELECT @IDlist = COALESCE(@IDlist + ', ', '') + CAST(id AS varchar(5)) FROM tbl
  3. SELECT @IDlist

Report this snippet  

You need to login to post a comment.