Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
by using tables i am getting output as follows,

EmpName      Place          Dept    income     

   A        Chennai          IT      20
   B        Chennai          IT      30
   C        Chennai          IT      40
   D        Chennai          CSE     30
   A        Chennai          CSE     50
   B        Chennai          CSE     40
   C        Chennai          CSE     10
   D        Chennai          CSE     70
   A        Bangalore        IT      20
   B        Bangalore        IT      30
   C        Bangalore        IT      40
   D        Bangalore        IT      80
   A        Bangalore        EEE     20
   B        Bangalore        EEE     30
   C        Bangalore        EEE     40
   D        Bangalore        EEE     80



I need output as follows


Place           Dept                A      B     C     D

Chennai          IT                20     30    40    30
Chennai          CSE               50     40    10    70 
Bangalore        IT                20     30    40    80 
Bangalore        EEE               20     30    40    80 

can you please help me...ASAP...
Posted

SQL
select place,dept,[A],[B],[C],[D] 
from TableName
pivot 
(
    sum(income) 
    for empname in ([A],[B],[C],[D])
)as pvttbl

Happy Coding!
:)
 
Share this answer
 
SQL
SELECT PLACE, DEPT, A, B, C, D FROM
(
SELECT EMPNAME, PLACE, DEPT, INCOME FROM EMPLOYEE
)X
PIVOT (SUM(INCOME) FOR EMPNAME IN (A, B, C, D)) AS PVT



THIS IS YOUR QUERY FOR YOUR PROBLEM.
 
Share this answer
 
Comments
itsureshuk 27-May-13 1:34am    
Here A,B,C,D Employee Name more than 100 rows is there,,,,i cant directly pass

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