我試圖運行下面的查詢,但對於在我的Case
語句中有兩個要求都被拔出的人,當我只想要單個記錄被拔出時,即使它們被拔出有兩個條件。Select Statement中的Case語句
SELECT DISTINCT
SyCampus.Descrip AS 'Campus',
dbo.rpt_adAttendanceDetail_vw.instructorname AS 'Instructor Name',
dbo.rpt_adAttendanceDetail_vw.classcode AS 'Class Code',
dbo.rpt_adAttendanceDetail_vw.section AS 'Section',
dbo.rpt_adAttendanceDetail_vw.classdescrip AS 'Class',
RTRIM(SyStudent.FirstName) + ' ' + ' ' + RTRIM(SyStudent.LastName) AS 'Student Name',
dbo.rpt_adAttendanceDetail_vw.stunum AS 'Student Number',
CASE WHEN CmEvent.CmtemplateID IN (714, 716, 732,734)THEN 'YES' ELSE 'NO' END AS 'Instructor Contact'
FROM
dbo.rpt_adAttendanceDetail_vw
JOIN
SyStudent
ON SyStudent.SyStudentID = dbo.rpt_adAttendanceDetail_vw.SyStudentID
JOIN
SyCampus
ON Sycampus.SycampusID = SyStudent.SyCampusID
JOIN
CmEvent
ON CmEvent.SyStudentID = SyStudent.SyStudentID
WHERE dbo.rpt_adAttendanceDetail_vw.AttMin = '0'
AND dbo.rpt_adAttendanceDetail_vw.date = DATEADD(d, DATEDIFF(d, 0, GETDATE()), 0) -1
AND SyStudent.SySchoolStatusID IN (13, 129, 130, 132, 72, 59, 122, 14)
AND dbo.rpt_adAttendanceDetail_vw.attendtype <> 'E'
AND CmEvent.CmEventStatusid = '2'
什麼是方言?微軟的SQL Server?其他? – ssarabando
'CASE'永遠不會重複你的行 - 它會返回yes或no。 – dezso