创建一个名为StuInfo的存储过程,要求完成以下功能:在student表中查询08级学生的学号,姓名性别出生日期和电话。

超人会飞 2012-05-31 10:38:52
create procedure StuInfo
@sno varchar(8)
as
select sno,sname,sex,birthday,phone
from student
where student.sno=@sno


exec StuInfo @sno like '08%'
//exec StuInfo substring(sno,1,2)='08'

但是上面的代码会运行出错,不知道怎么回事?
如果改成
exec StuInfo @sno='08%' 能够运行,但只会出现边框,但是没有输出该有的结果
新建student表中含有三个08开头的学号(0801,0802,0803),正常的运行肯定会出现结果

但是改成exec StuInfo @sno= '0801'就能得出正确的结果

麻烦各位知道的讲解一下
...全文
2761 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xutianfu123 2012-06-03
  • 打赏
  • 举报
回复
create procedure StuInfo
@sno varchar(8)
as
BEGIN
select sno,sname,sex,birthday,phone
from student
where sno=@sno and sno like '08%'
END

EXEC StuInfo

bean_sql 2012-06-01
  • 打赏
  • 举报
回复
没尝试过用表达式...
xuewuhen20 2012-06-01
  • 打赏
  • 举报
回复
好像存储过程的的参数不允许是一个表达式哦
超人会飞 2012-05-31
  • 打赏
  • 举报
回复
1楼的错误和我一样,有数据但是输不出来!
2楼的程序我运行了一下,是对的。
但是有些搞不懂
(@sno+'%')这种形式好像没见过,
我写的exec StuInfo @sno like '08%'
,不知道为什么错了?
百年树人 2012-05-31
  • 打赏
  • 举报
回复
create procedure StuInfo
@sno varchar(8)
as
select sno,sname,sex,birthday,phone
from student
where student.sno like @sno+'%'
go

exec StuInfo '08'
--小F-- 2012-05-31
  • 打赏
  • 举报
回复
create procedure StuInfo
@sno varchar(8)
as
select sno,sname,sex,birthday,phone
from student
where sno=@sno and sno like '08%'

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧