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.
Hi,I have table emp projectABCD P1ABCD P2ABCD P3PQR P2PQR P4XYZ P3XYZ P4I need help in writing a query to format,emp PROJECTABCD P1,P2,P3PQR P2,P4XYZ P3,P4Any help very much appreciatedthanks in advance
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2009-03-16 : 13:56:57
you need to create a UDF like this
CREATE FUNCTION GetProjects(@Emp varchar(100))RETURNS Varchar(8000) ASBEGINDECLARE @Ret varchar(8000)SELECT @Ret=COALESCE(@Ret+',','') + PROJECT FROM TableWHERE emp=@EmpRETURN @RetEND then use it like belowSELECT DISTINCT emp,dbo.GetProjects(emp)FROM Table