我是ASP新手。我需要帮助来创建报告。我有一个SQL查询
SELECT StudentID, StudentName, SectionID, ExamID, SubjectID, Subject, Marks, TotalMarks
, Percentage, Grade, (SELECT MAX(Marks) AS Exp1
FROM tbl_Result
WHERE (SectionID = @SectionID)
AND (SubjectID = view_StudentResult.SubjectID)) AS SubjectToper
FROM view_StudentResult WHERE (StudentID = @StudentID)
当我在报告中显示时,所有其他字段都会根据需要填充,但SubjectToper
字段显示为空白。有人可以帮助你以优雅的方式做到这一点吗?
答案 0 :(得分:0)
尝试使用 Exp1
填充该字段。
您正在为整个子查询提供别名 SubjectToper
,但实际选择的是别名Exp1
。
结帐this explanation of sub queries。 特别是最后一个将子查询分配给值的示例。也许这会奏效?
您的SQL看起来像:
SELECT StudentID, StudentName, SectionID, ExamID, SubjectID, Subject, Marks, TotalMarks, Percentage, Grade,
SubjectToper = (SELECT MAX(Marks) FROM tbl_Result
WHERE (SectionID = @SectionID) AND (SubjectID = view_StudentResult.SubjectID))
FROM view_StudentResult WHERE (StudentID = @StudentID)
注意我删除了别名并将子查询分配给了SubjectToper。
我希望这有效,否则我害怕我没有想法。