私の次のクエリでは、@TMarks、@OMarks、@Percentage に 0、0、0 をそれぞれ設定したいのですが、それらで使用された select ステートメントが何も返さない場合
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