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

I have 3 tables called timetablemaster,timetabledetails and staff.

Here are my table Structure

timetablemaster

ttId, ttTitle, classCode, sectionCode, startTime, validFrom, validTo, startDate, endDay, noOfClasses


timetabledetails

ttDetailsId, ttId, day, period, subjectCode, staffCode



staff

staffId, staffCode, firstName


SQL
select  s.firstName as Staff, tm.classCode as Class, td.day as Day, td.period as Periods
from timetabledetails td, timetablemaster tm, staff s where s.staffCode = td.staffCode and td.ttId = tm.ttId and td.staffCode like 'S01';



From this query i am getting this format


Staff | Class | Day | Period |

Abc | STD1 | Monday | 1 |
Abc | STD1 | Tuesday| 5 |
Abc | STD1 | Wednesday | 4 |
Abc | STD1 | Thursday | 2 |
Abc | STD1 | Friday | 3 |
Abc | STD1 | Saturday | 3 |
Abc | STD2 | Monday | 5 |
Abc | STD2 | Tuesday| 4 |
Abc | STD2 | Wednesday | 3 |
Abc | STD2 | Thursday | 2 |
Abc | STD2 | Friday | 1 |
.
.
.
.


But I need to display the Table in this format in Gridview


|Monday|

StaffName | Period1 | Period2 | Period3 | Period4 | Period5

Abc | STD1 | STD2 | STD3 | STD1 | STD2
.
.
Xyz | STD3 | STD5 | STD1 | STD4 | STD1
Pqr | STD2 | STD3 | STD4 | STD1 | STD3
.
.
.
.


Anybody know how to do this? Thanks very much!
Posted
Updated 20-Mar-14 4:09am
v15

1 solution

 
Share this answer
 
v2
Comments
[no name] 20-Mar-14 9:24am    
Hai Jas, I am not able to do it from u r given link, can u please help me
Tom Marvolo Riddle 20-Mar-14 23:58pm    
[no name] 21-Mar-14 0:02am    
I am retrieving table from Database and storing in DataTable and from Datatable i am trying to make that format... which is not happening ... is there any other way
Tom Marvolo Riddle 21-Mar-14 0:15am    
Afaik PIVOT is the only way to achieve this.Just refer the link and customize it
[no name] 21-Mar-14 0:16am    
I tried but i am not getting :(

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