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.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 Pivot Transformation

Author  Topic 

komal403
Starting Member

7 Posts

Posted - 2010-04-08 : 01:05:32

My Table
Course Attempt Grade Sex Age percentile
CS101 1 A M 23 83
CS101 1 B F 22 62
CS101 1 A F 45 81
CS101 2 B M 37 60
EE201 1 A M 23 96
EE201 1 B F 22 69
EE201 1 A F 45 82
EE201 2 B M 37 61

OutPut Result

Attempt Grade Sex Age Cs101 EE201
1 A M 23 83 96
1 B F 22 62 69
1 A F 45 81 82
2 B M 37 60 61

I 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 Help






komal

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 EE201
FROM Table
GROUP BY Attempt, Grade, Sex, Age
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

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 EE201
FROM Table
GROUP BY Attempt, Grade, Sex, Age


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/


THANK U VISHAK!!!!!

ITS Working



komal
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-08 : 11:34:10
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -