2015-09-28 188 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 ;) –