Sql combine 2 rows to one

Posted by Yan on Stack Overflow See other posts from Stack Overflow or by Yan
Published on 2010-06-03T10:52:55Z Indexed on 2010/06/03 11:14 UTC
Read the original article Hit count: 242

Filed under:
|
|

Hi ,

i have this table Testers

employee name
------------
Sam Korch
dan mano

i want to combine tow rows to one, it will be "Sam Korch,Dan Mano"

i have this query

select @theString = COALESCE(@theString + ',', '') + EmployeeName 
  from Testers join vw_EKDIR on Testers.TesterGlobalId = vw_EKDIR.GlobalID
 where TestId = 31   

it working but i dont want to do select i want the result will be in @thestring

so i try to do this query

set @theString = (
    select  @theString = COALESCE(@theString + ',', '') + EmployeeName 
      from Testers join vw_EKDIR on Testers.TesterGlobalId = vw_EKDIR.GlobalID
     where TestId = 31 
    )

it is not working ... i want @thestring will be the result.

any idaes ?

thanks

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server