Click here to Skip to main content
15,886,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried several but i did not get the correct output

C#
Select * from Tb_SCh_TIme_Table;

Output shows as follows;

Date Session Course FAculty_Code

1/14/2013 3 AFF PN
1/21/2013 2 AFF NR
1/21/2013 1 AFF GS
1/24/2013 4 AFF VB
1/14/2013 4 AFF CM
1/16/2013 3 AFF NR
1/21/2013 2 AFF GS

I tried the below query as follows;

SQL
TRANSFORM First(Tb_SCh_TIme_Table.Faculty_Code) AS a
SELECT 
Tb_SCh_TIme_Table.Course
FROM 
Tb_SCh_TIme_Table
GROUP BY 
Tb_SCh_TIme_Table.Course
PIVOT 
Tb_SCh_TIme_Table.Session


Output as follows;

Course 1 2 3 4
AFF GS NR NR VB
ARPA VB VB GS
CTF NR PN
ECDIS VB PN PN
ERSM CM GS RK
LGTF VB NR
MFA PN NR PN
PH2 PN RK NR
REO NR GS NR VB
TASCO GS CM CM GS
TFC CM GS GS

From the first query select * from Tb_SCh_TIme_Table;the Second ouput is not matching.
from the query what is the mistake. help me.

if AFF course is taken by same session and differnet Facultycode means output is not correctly showing.it is not matching with select * from Tb_SCh_TIme_Table;
what is the mistake in above query help me. please
Posted
Updated 25-Jan-13 0:34am
v2

1 solution

Since there are multiple Faculties for same session for a single course, you have to include Date in the query. Because the sessions belongs to different dates.

Use the following query.

SQL
TRANSFORM First(Tb_SCh_TIme_Table.Faculty_Code) AS a
SELECT Tb_SCh_TIme_Table.Date, Tb_SCh_TIme_Table.Course
FROM Tb_SCh_TIme_Table
GROUP BY Tb_SCh_TIme_Table.Date, Tb_SCh_TIme_Table.Course
PIVOT Tb_SCh_TIme_Table.Session;
 
Share this answer
 
v2

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