我正在尝试运行以下查询,但是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'