Как динамически задать параметры в представлении (SQL server 2012) и позже вызвать представление в хранимой процедуре?
Вот такой вид.
CREATE VIEW [dbo].[View_Sum_Student_Marks] AS SELECT TOP (100) PERCENT StudentID, SUM(Scie + Maths + Engl + Sets + Agri + SStud + Moral + Gen + Pract) AS Total, CAST(ROUND(SUM(Scie + Maths + Engl + Sets + Agri + SStud + Moral + Gen + Pract) / 9, 2) AS decimal(12, 2)) AS Average FROM dbo.student_results WHERE (ExamID = 2) AND (AcademicYear = 2017) GROUP BY StudentID ORDER BY Total DESC
Я хочу установить Экзамен и академический год динамически, то я хочу вызвать представление из процедуры, как показано ниже
ALTER PROCEDURE [dbo].[proc_Top50Form1] -- Add the parameters for the stored procedure here @examid int, @academicyear int AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; SELECT TOP (100) PERCENT dbo.students.StudentID, dbo.students.Fistname, dbo.students.Lastname,dbo.students.Gender, dbo.students_overall_analysis.Points, dbo.students_overall_analysis.Grade, dbo.View_Sum_Student_Marks.Total AS [Subjects Total], dbo.View_Sum_Student_Marks.Average AS [Subjects Average], students_overall_analysis.AcademicYear ,dbo.classes.ClassName,exam_types.ExamType FROM dbo.View_Sum_Student_Marks INNER JOIN dbo.students ON dbo.View_Sum_Student_Marks.StudentID = dbo.students.StudentID INNER JOIN dbo.classes ON dbo.students.AcademicClass = dbo.classes.ID INNER JOIN dbo.students_overall_analysis ON dbo.students.StudentID = dbo.students_overall_analysis.StudentID INNER JOIN exam_types ON students_overall_analysis.ExamID = exam_types.ID WHERE (dbo.students_overall_analysis.ExamID = @examid) AND (dbo.students_overall_analysis.AcademicYear = @academicyear) AND (classes.ClassName LIKE '%1%') ORDER BY dbo.students_overall_analysis.Points DESC,[Subjects Total] DESC
Что я уже пробовал:
Привет, ребята, не могли бы вы мне помочь? Я работаю над системой управления школой, но застрял и нуждаюсь в помощи.