0

在我的存储过程中,我想获取StudentElectivePaper.SubjectPaperID等于传递的参数值或根本没有值(空值)的数据。

我尝试过 OR 语句,例如

StudentElectivePaper.SubjectPaperID = @SubjectPaperID OR StudentElectivePaper.SubjectPaperID IS NULL

但它并没有产生丰硕的成果。请帮忙!

ALTER PROCEDURE [dbo].[StudentElectiveMappings]
    @SubjectPaperID INT,
    @ExamPaperID INT,
    @ExamID INT,
    @SubjectElectiveID INT,
    @ExamPaperTypeID INT,
    @LCID INT = NULL
AS
BEGIN
    SELECT DISTINCT
        ViewStudentExamApplicant.StudentID,
        ViewStudentExamApplicant.ExamRollNo,
        CASE 
           WHEN StudentElectivePaper.ID IS NULL 
              THEN CAST(0 AS BIT) 
              ELSE CAST(1 AS BIT) 
        END AS 'IsMapped'
    FROM
        StudentElectivePaper
    RIGHT OUTER JOIN 
        ViewStudentExamApplicant ON StudentElectivePaper.ExamPaperID = ViewStudentExamApplicant.ExamPaperID
                                 AND StudentElectivePaper.ExamID = ViewStudentExamApplicant.ExamID
                                 AND ViewStudentExamApplicant.StudentID = StudentElectivePaper.StudentID
    WHERE 
        ViewStudentExamApplicant.ExamID = @ExamID
        AND ViewStudentExamApplicant.ExamPaperID = @ExamPaperID
        AND StudentElectivePaper.SubjectPaperID = @SubjectPaperID
        AND ViewStudentExamApplicant.ExamPaperTypeID = @ExamPaperTypeID
        AND StudentElectivePaper.SubjectElectiveID = @SubjectElectiveID
        AND (ViewStudentExamApplicant.LCID = @LCID OR @LCID IS NULL)
    ORDER BY 
        IsMapped DESC, ViewStudentExamApplicant.ExamRollNo
4

0 回答 0