Please see my script below,
This is one of the msdn user request but as he is newbie unable to put ddl and dmls.. but all he wants is doing pivot on values.. but I'm trying the same using dynamic pivot which I'm not able to achieve. Help is appreciated.
Table Script:
create table #temp( ProjectNO int,projectname varchar(10),client varchar(10),programmers varchar(10)); declare @cols AS nvarchar(MAX) ,@QUERY AS NVARCHAR(MAX); Insert into #temp Select 01 , 'ave' , 'zica' , 'dee' UNION Select 01, 'ave', 'zica ', 'law' UNION Select 01 ,'ave', 'zica', 'amy' UNION Select 01 , 'ave' , 'rowan' , 'dee' UNION Select 01 ,'ave' ,'rowan' ,'law' UNION Select 01 ,'ave' ,'rowan' ,'amy' Select * from #temp
Question 1: Desired output:
ProjectNO.PrjtnameClt1Clt2Prog1Prog2Prog301 ave zica rowan dee law amy
Question 2: Query:
Select distinct Replace((select distinct convert(char(8),client) from #temp FOR XML path('')) ,'";;#;;"',' ') as clients FROM #temp GROUP BY ProjectNO
In the above query I'm doing xml path and I'm getting result in single row like
clients
rowan zica
Instead can I get result like below using xml path?
client1 client2
rowan zica
- please mark correct answers