Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im use pivot table query for display the data...

in the Abc table 4 columns like SID (auto increment), StudentID, Attendance, Day.

SQL
select * from Abc
pivot (max (Attendance) for Day in ([Day1],[Day2],[Day3])) as DayWise

Output :-

 SID    StudentID    Day1   Day2   Day3
----------------------------------------
  1       101         A     null   null
  2       101        null    A     null
  3       101        null   null    A
  4       102         A     null   null
  5       103        null    A     null

But i want this type of output :-

StudentID    Day1   Day2   Day3
---------------------------------
101           A      A      A
102           A      A     null

So how can i do this....
Thanx in advance...
Posted
Updated 30-May-14 1:23am
v4

 
Share this answer
 
v2
Comments
Harnis Findoliya 30-May-14 7:44am    
yes i learn it... but when im take the primary key in the table then it is not work well like above example...
 
Share this answer
 
Comments
Harnis Findoliya 30-May-14 7:47am    
yes i learn it... but when im take the primary key in the table then it is not work well like above example...
Animesh Datta 30-May-14 8:03am    
what problem then showing ?
Harnis Findoliya 30-May-14 8:21am    
i want to show the one student attendance in only one row...
SQL
select distinct studentid,
(select attendance from abc where day='Day1' and abc.studentid=t1.studentid) day1,
(select attendance from abc where day='Day2' and abc.studentid=t1.studentid) day2,
(select attendance from abc where day='Day3' and abc.studentid=t1.studentid) day3
from abc t1
 
Share this answer
 

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