Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
;WITH MyCte(EType,EventDate) AS
(
SELECT 'Exam',E.DateOfExam FROM tbl_ExamCreation E
UNION ALL
SELECT 'Lecture',LS.StartDateTime FROM tbl_LectureScheduling LS
)
 
SELECT EType,EventDate FROM MyCte ORDER BY 1 DESC 


------------------------------------

SQL
SELECT     tbl_ExamCreation.Exam_ID, tbl_ExamCreation.ExamName, tbl_ExamAttendence.StudentID, tbl_ExamAttendence.Exam_ID AS Expr1, 
                      tbl_LectureAttendence.StudentID AS Expr2, tbl_LectureAttendence.LectureScheduleID, tbl_LectureAttendence.status, tbl_Lectures.LectureID, 

tbl_Lectures.LectureName,
                       tbl_LectureScheduling.LectureScheduleID AS Expr3, tbl_LectureScheduling.LectureID AS Expr4, tbl_LectureScheduling.StartDateTime, 
                      tbl_ExamCreation.DateOfExam
FROM         tbl_LectureScheduling INNER JOIN
                      tbl_LectureAttendence ON tbl_LectureScheduling.LectureScheduleID = tbl_LectureAttendence.LectureScheduleID INNER JOIN
                      tbl_Lectures ON tbl_LectureScheduling.LectureID = tbl_Lectures.LectureID CROSS JOIN
                      tbl_ExamCreation INNER JOIN
                      tbl_ExamAttendence ON tbl_ExamCreation.Exam_ID = tbl_ExamAttendence.Exam_ID
WHERE     (tbl_ExamAttendence.StudentID = 1044) AND (tbl_LectureAttendence.StudentID = 1044)
Posted
Updated 11-Aug-14 18:16pm
v2
Comments
Dilan Shaminda 12-Aug-14 0:18am    
combine which queries? Question is not clear
Sergey Alexandrovich Kryukov 12-Aug-14 0:26am    
This is not a question, sorry. Well, why not combining them?..
—SA
m-shraddha 12-Aug-14 0:40am    
I want to combine 1st and 2nd block of the query

To combine queries you should first have the same number of columns and they should logically be the same type, then you can use UNION like you have in the first "block".
 
Share this answer
 
SQL
;WITH MyCte(EType,EventDate,EName,EStatus) AS
(
SELECT     'Exam' AS Expr1, E.DateOfExam, E.ExamName,tbl_ExamAttendence.status
FROM         tbl_ExamCreation AS E INNER JOIN
                      tbl_ExamAttendence ON E.Exam_ID = tbl_ExamAttendence.Exam_ID
WHERE     (tbl_ExamAttendence.StudentID = 1044)
UNION ALL
SELECT     'Lecture' AS Expr1, LS.StartDateTime, tbl_Lectures.LectureName,tbl_LectureAttendence.status
FROM         tbl_LectureScheduling AS LS INNER JOIN
                      tbl_LectureAttendence ON LS.LectureScheduleID = tbl_LectureAttendence.LectureScheduleID INNER JOIN
                      tbl_Lectures ON LS.LectureID = tbl_Lectures.LectureID
WHERE     (tbl_LectureAttendence.StudentID = 1044)
)

SELECT TOP 5 EType,EventDate,EName,EStatus FROM MyCte ORDER BY EventDate DESC
 
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