
t-sql 存储过程
ALTERprocedureproc_等级@sidintasdeclare@aintselect@a=scorefromchoiceswheresid=@sidprint...
ALTER procedure proc_等级
@sid int
as
declare @a int
select @a=score from choices where sid=@sid
print @a
if @a>60
begin
if @a<=70
update choices set 成绩等级='D'
else if @a<=80
update choices set 成绩等级='C'
else if @a<=90
update choices set 成绩等级='B'
else update choices set 成绩等级='A'
end
ELSE
update choices set 成绩等级='E'
EXEC proc_等级 @SID=2003787
执行此存储过程,结果所有的学生等级都变成E,请问下是哪里出错了 展开
@sid int
as
declare @a int
select @a=score from choices where sid=@sid
print @a
if @a>60
begin
if @a<=70
update choices set 成绩等级='D'
else if @a<=80
update choices set 成绩等级='C'
else if @a<=90
update choices set 成绩等级='B'
else update choices set 成绩等级='A'
end
ELSE
update choices set 成绩等级='E'
EXEC proc_等级 @SID=2003787
执行此存储过程,结果所有的学生等级都变成E,请问下是哪里出错了 展开
1个回答
展开全部
declare @a int
select @a=score from choices where sid=@sid
这个查询出来的结果肯定小于60,赋值给@a,再用if语句判断,不执行If语句里面begin和end之间的语句,直接else,把所有的学生等级都设置为‘E'了。
解决办法:
首先select score from choices where sid = @sid;看看结果是不是小于六十,如果是,则的确是上面的错误。
其次,在使用update 语句时后面必须跟一个where条件限制更新行,否则全部都更新了,这是大忌!!!
select @a=score from choices where sid=@sid
这个查询出来的结果肯定小于60,赋值给@a,再用if语句判断,不执行If语句里面begin和end之间的语句,直接else,把所有的学生等级都设置为‘E'了。
解决办法:
首先select score from choices where sid = @sid;看看结果是不是小于六十,如果是,则的确是上面的错误。
其次,在使用update 语句时后面必须跟一个where条件限制更新行,否则全部都更新了,这是大忌!!!

2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件...
点击进入详情页
本回答由光点科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询