This one automatically excludes the trailing comma, unlike most of the other answers.
DECLARE @csv VARCHAR(1000) SELECT @csv = COALESCE(@csv + ',', '') + ModuleValue FROM Table_X WHERE ModuleID = @ModuleID
(If the ModuleValue
column isn't already a string type then you might need to cast it to a VARCHAR
.)