日期:2014-05-18  浏览次数:20703 次

这个存储过程,出错时怎么回事??亲
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 getCourseName
as
begin
  select distinct course.courseName from grade,course where grade.courseID=course.courseID
end
go ---这里加个GO

create procedure stat
@courseName nchar(20),
@avgGrade float output
as  
  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