当前位置: 代码迷 >> Sql Server >> 这个存储过程,出错时咋回事?亲
  详细解决方案

这个存储过程,出错时咋回事?亲

热度:66   发布时间:2016-04-27 13:00:09.0
这个存储过程,出错时怎么回事??亲
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
  相关解决方案