sql server存储过程出错
--编写存储过程完成学生借用教室的功能,如果申请的教室有冲突,请给出提示。
create procedure[borrow_classroom_1]
(@Building_name [Varchar](50),--学生输入的教学楼号
@Classroom_id [Varchar](50),--学生输入的教室号
@Student_id [Varchar](50),--学生的ID
@Date [Datetime](8),--学生输入的教室日期
@Period [Varchar](50),--学生输入的借教室的时段
@Fun [Varchar](50),--学生输入的教室用途
@State [Varchar](50),--在存储过程中使用的变量,判断教室的使用状态
@bID [Varchar](50),--在存储过程中使用的变量,更新表时暂时存放教学楼号
@success [int] = output)--返回值,作为标志借教室是否成功的标志
as
begin
@success=0;
select CM_Classroom_fun into @State
from CM_Classroom ,CM_Building
where CM_Classroom_id=@Classroom_id and CM_Building.CM_Building_id=CM_Classroom.CM_Building_id
and CM_Building.CM_Building_name=@Building_name;
if @State is null then
--如果教室的使用状态为空闲,
--找到与教学楼名称相对应的教学楼编号
select CM_Building_id into @bID from CM_Building where CM_Building_name=@Building_name;
--更新教室表的相应教室的使用状态
update CM_Classroom set CM_Classroom_fun=@Fun where CM_Building_id=@bID
and CM_Classroom_id=@Classroom_id;
--插入一条借用教室的新纪录
Insert into CM_Borrow(CM_Building_id,CM_Classroom_id,CM_Student_id,CM_Borrow_date,
CM_Borrow_period,CM_Borrow_state)
Values(@bID,@Classroom_id,@Student_id,@Date,@Period,1);
--返回结果为true,表示借教室成功
@success = 1;
end if;
end
错误:
消息 102,级别 15,状态 1,过程 borrow_classroom_1,第 14 行
'@success' 附近有语法错误。
消息 102,级别 15,状态 1,过程 borrow_classroom_1,第 15 行
'@State' 附近有语法错误。
消息 156,级别 15,状态 1,过程 borrow_classroom_1,第 19 行
关键字 'then' 附近有语法错误。
消息 102,级别 15,状态 1,过程 borrow_classroom_1,第 22 行
'@bID' 附近有语法错误。
消息 102,级别 15,状态 1,过程 borrow_classroom_1,第 31 行
'@success' 附近有语法错误。