Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I have a two tablestable1 magname ABCXYZPQRJKLtable2 magname empname ABC emp1 ABC emp2 ABC emp3XYZ emp4XYZ emp5PQR emp6JKL emp7JKL emp8I want to write a stored procedure which will return the output as followmagname empname ABC emp1,emp2,emp3XYZ emp4,emp5PQR emp6JKL emp7,emp8please give me some idea
SELECT t1.magname,LEFT(el.emplist,LEN(el.emplist)-1)FROM table1 t1CROSS APPLY(SELECT empname + ',' AS [text()] FROM table2 WHERE magname=t1.magname FOR XML PATH(''))el(emplist)
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-09-26 : 00:50:37
and if using sql 2000 try any of methods given in below linkhttp://www.projectdmx.com/tsql/rowconcatenate.aspx