在我的以下查询中,如果与它们一起使用的选择语句不返回任何内容,我想分别在 @TMarks、@OMarks、@Percentage 中设置 0、0、0
create procedure [dbo].[TestRecordSelectMInfo]
@GRNo varchar(4),
@SessionId numeric(1),
@TestTypeId numeric(1),
@TMarks int output,
@OMarks numeric(4) output,
@Percentage numeric(4) output,
@Grade varchar(4) output
as
begin
SELECT Subjects.Subject, Marks.TotalMarks, Marks.PassingMarks, TestRecord.Marks, Result = case when TestRecord.Marks = 'A' then 'A' else case when cast(TestRecord.Marks as numeric) < Marks.PassingMarks then 'F' else 'P' end end FROM Subjects INNER JOIN Marks ON Subjects.SubjectId = Marks.SubjectId INNER JOIN TestRecord ON Subjects.SubjectId = TestRecord.SubjectId AND Marks.TestTypeId = TestRecord.TestTypeId where TestRecord.SessionId = @SessionId and TestRecord.TestTypeId = @TestTypeId and TestRecord.GRNo = @GRno
set @TMarks = (select sum(Marks.TotalMarks) from Marks inner join TestRecord on Marks.TestTypeId = TestRecord.TestTypeId and Marks.SubjectId = TestRecord.SubjectId where TestRecord.SessionId = @SessionId and TestRecord.TestTypeId = @TestTypeId and TestRecord.GRNo = @GRNo and TestRecord.Marks <> 'A' and cast(TestRecord.Marks as numeric) > Marks.PassingMarks )
set @OMarks = (select sum(cast(TestRecord.Marks as numeric)) from Marks inner join TestRecord on Marks.TestTypeId = TestRecord.TestTypeId and Marks.SubjectId = TestRecord.SubjectId where TestRecord.SessionId = @SessionId and TestRecord.TestTypeId = @TestTypeId and TestRecord.GRNo = @GRNo and TestRecord.Marks <> 'A' and cast(TestRecord.Marks as numeric) > Marks.PassingMarks)
set @Percentage = @OMarks / @TMarks * 100;
set @Grade = case
when @Percentage < 50
then
'NIL'
else
case
when @Percentage < 60
then
'C'
else
case
when @Percentage < 70
then
'B'
else
case
when @Percentage < 80
then
'A'
else
case
when @Percentage <= 100
then
'A+'
else
'FAIL'
end
end
end
end
end
end
GO