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.
Author |
Topic |
komal403
Starting Member
7 Posts |
Posted - 2010-04-08 : 01:05:32
|
My Table Course Attempt Grade Sex Age percentileCS101 1 A M 23 83CS101 1 B F 22 62CS101 1 A F 45 81CS101 2 B M 37 60EE201 1 A M 23 96EE201 1 B F 22 69EE201 1 A F 45 82EE201 2 B M 37 61OutPut ResultAttempt Grade Sex Age Cs101 EE2011 A M 23 83 961 B F 22 62 691 A F 45 81 822 B M 37 60 61I tried using Pivot Transformation but its not working....any easier way to convert Rows to column????I donot know wether my query is wrong or right? Plz Helpkomal |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-08 : 01:24:12
|
[code]SELECT Attempt, Grade, Sex, Age,MAX(CASE WHEN Course='CS101' THEN percentile ELSE NULL END) AS Cs101,MAX(CASE WHEN Course='EE101' THEN percentile ELSE NULL END) AS EE201FROM TableGROUP BY Attempt, Grade, Sex, Age[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
komal403
Starting Member
7 Posts |
Posted - 2010-04-08 : 11:31:54
|
quote: Originally posted by visakh16
SELECT Attempt, Grade, Sex, Age,MAX(CASE WHEN Course='CS101' THEN percentile ELSE NULL END) AS Cs101,MAX(CASE WHEN Course='EE101' THEN percentile ELSE NULL END) AS EE201FROM TableGROUP BY Attempt, Grade, Sex, Age ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/THANK U VISHAK!!!!!ITS Working
komal |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-08 : 11:34:10
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|