+2  A: 
DECLARE @foos VARCHAR(4000)

SELECT @foos = COALESCE(@foos + ',', '') + Foo FROM Bar

SELECT @foos AS Foo
LukeH
A: 

Ross,

this should get you started.

  DECLARE @r VARCHAR(8000)
  SELECT @r = (SELECT DISTINCT Foo + ', ' FROM Bar FOR XML PATH(''))
  IF @r IS NOT NULL AND @r <> '' SET @r = SUBSTRING(@r, 1, LEN(@r)-1)
  SELECT @r
Lieven
A: 

Try the following

declare @joined varchar(max)
set @joined = ''

select  @joined = @joined + IsNull(Foo + ',', '')
from    Bar (nolock)

--; Drop last "," if necessary
set @joined = substring(@joined, 1, len(@joined) - (case when len(@joined) > 0 then 1 else 0 end))
select  @joined as foo
Sung Meister
+1  A: 
SELECT
    ( 
    SELECT
      CASE
        WHEN ROW_NUMBER() OVER(ORDER BY bar) = 1 THEN ''
        ELSE ', '
      END + CAST(bar AS VARCHAR)
    FROM foo
    ORDER BY bar
    FOR XML PATH('')
    )
Quassnoi
This looks "elegant" but quite slow
Sung Meister
Concatenated string do not tend to consist of millions records. For a dozen records which will most probable will there, it will work in a flash.
Quassnoi
In my case, this would only be applied to a few records and it could be used as a subquery in a select statement, which worked best for me.
Ross Goddard
A: 
Allan Simonsen
A: 
 select max(a),max(b),max(c) from
 (
      select 'a' as a,null as b,null as c
      union
      select null,'b',null
      union
      select null,null,'c'
 ) as x
Fredou