Posted By

mafro on 07/25/08


Tagged


Versions (?)

Set Comma Separated List


 / Published in: SQL
 

Build a comma-separated list of ids.

  1. declare @site_ids varchar(1000)
  2. SET @site_ids = ''
  3.  
  4. --concat'd list of site_ids
  5. SELECT @site_ids = @site_ids + ', ' + convert(varchar,site_id)
  6. FROM tbl_site
  7.  
  8. --remove starting and trailing commas
  9. SET @site_ids = substring(@site_ids, 3, len(@site_ids)-3)
  10.  
  11. print @site_ids

Report this snippet  

You need to login to post a comment.