2015-09-28 153 views

回答

4

嘗試添加括號()在以下幾點:

WHERE ([email protected] OR @CourseID=0) 
     AND 
     ([email protected] OR @ClassID=0) 
     AND 
     ([email protected] OR @ClassSectionID=0) 
     AND 
     SD.StudentID<>SS.StudentID 
+0

對不起,沒有工作。 – Jithin

+0

@Jithin什麼不工作?提供樣本數據和期望的結果。 –

+0

在搜索點擊我需要顯示StudentIDs那些不在SS.StudentID。 – Jithin

1

可以使用NOT IN選擇那些StudentIDs不存在StudentSubjectMapping

INNER JOIN StudentSubjectMapping SS ON SM.StudentID=SS.StudentID 
WHERE ([email protected] OR @CourseID=0) 
    AND ([email protected] OR @ClassID=0) 
    AND ([email protected] OR @ClassSectionID=0) 
    AND (SD.StudentID NOT IN (SELECT StudentID FROM StudentSubjectMapping)) 
+0

幾乎是正確的。無需使用INNER JOIN。感謝您的支持。 – Jithin

1

感謝您的支持。答:

WHERE 
    ([email protected] OR @CourseID=0) 
    AND 
    ([email protected] OR @ClassID=0) 
    AND 
    ([email protected] OR @ClassSectionID=0) 
    AND 
    SM.StudentID NOT IN (SELECT StudentID FROM StudentSubjectMapping) 
+0

是的,並用於記錄:查看SQL運算符優先級;至少AND & OR ;) –