Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

Hi all This is my scenario.
Please check out this link> it will explain in detail.


http://snag.gy/ffC8r.jpg[^]


Im using MySQL and C#, I think it will better to understand so I created this Image.

Thanks :)
Posted
Comments
Jameel VM 28-Feb-13 0:28am    
did you try anything?

1 solution

I think this is exactly what you want..

SQL
Declare @Colms varchar(max)=''
SELECT
       @Colms= Stuff((SELECT ', [' + cast(s as varchar(max))+']'
        FROM
        (select distinct AA as s from YYYY where id in (select id from xxxx)) x
        For XML PATH ('')),1,1,'')


exec('select  id,A,B,C,D,'+@Colms+'
from
(
   select p.*,q.AA,q.BB  from xxxx p left join YYYY q on p.id=q.id
) x
pivot
(
  max(BB)
  for AA in('+@Colms+')
)p ')
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900