Building a comma separated list?

Viewed 55048

I'm tryin to use SQL to build a comma separated list of cat_id's

the code is:

declare     @output varchar(max)
set         @output = null;
select @output = COALESCE(@output + ', ', '') + convert(varchar(max),cat_id)

edit: changed '' to null, STILL same. but the output im getting is like so:

, 66 , 23

the leading comma should not be there. What have i missed?

9 Answers
Related