create procedure getCourseName
as
select distinct course.courseName from grade,course where grade.courseID=course.courseID
create procedure stat @courseName nchar(20),@avgGrade float output
as
begin
declare @count int
declare @avgGrade float
declare @courseName Str
select @count =count(*),@avgGrade=avg(grade)from xsda,grade,course where xsda.no=
grade.no and grade.courseID=course.courseID and course.courseName like @courseName
select xsda.no as 学号,xsda.name as 姓名,grade.grade as 成绩 from xsda,grade,course
where xsda.no=grade.no and grade.courseID=course.courseID and course.courseName like
@courseName
return @count
end
消息 156,级别 15,状态 1,过程 getCourseName,第 4 行
关键字 'procedure' 附近有语法错误。
------解决方案--------------------
- SQL code
create procedure getCourseNameasbegin select distinct course.courseName from grade,course where grade.courseID=course.courseIDendgo ---这里加个GOcreate procedure stat@courseName nchar(20),@avgGrade float outputas begin declare @count int declare @avgGrade float ---这里已经声明过的变量,会报错的 declare @courseName nchar(20) ---这里已经声明过的变量,会报错的 select @count =count(*),@avgGrade=avg(grade)from xsda,grade,course where xsda.no= grade.no and grade.courseID=course.courseID and course.courseName like @courseName select xsda.no as 学号,xsda.name as 姓名,grade.grade as 成绩 from xsda,grade,course where xsda.no=grade.no and grade.courseID=course.courseID and course.courseName like @courseName return @count end go