Posted by: stylish February 24, 2008
SQL help
Login in to Rate this Post:     0       ?        

How do I transform a table into a comma separated values?? If I have an "employeeid"  as 1 that has taken different orders, I want to display in the result set like this

Employeeid           orderid

1                            1024,1025,1028,1029

I know only to display as column:

CREATE function dbo.fn_inonerow(@P_empid int)
returns @v_table table(employeeid int,orderid int)
As

Begin

Insert into @v_table(employeeid,orderid)

  Select               a.employeeid,a.orderid 
  From                orders a
  inner join           employees b
  on                       b.employeeid=a.employeeid
  Where                b.employeeid=@p_empid


Return
End

GO

 

Read Full Discussion Thread for this article