⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_48963.htm

📁 vc
💻 HTM
字号:
<p>
序号:48963 发表者:xqq 发表日期:2003-08-05 15:43:25
<br>主题:存储过程的执行状态问题!谢谢了!
<br>内容:题目:编写一个存储过程,查询NORTHWIND数据库中EMPLOYEES表中的数据,如果存在年龄超过50岁的用户,则返回用户数量,否则返回0<BR>做法:use northwind <BR>go<BR>if exists (select name from sysobjects where name='exp_ret'<BR>and type='p')<BR>drop proc exp_ret<BR>go<BR>create proc exp_ret <BR>as <BR>if exists (select count(distinct employeeid)from employees<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where (2003 - year(birthdate)) &gt;=50)<BR>return @@rowcount<BR>else return 0<BR>go<BR>运行如下:use northwind <BR>go<BR>declare @status int<BR>execute @status=exp_ret&nbsp;&nbsp;<BR>select 'procedure status'=@status<BR>go<BR>为什么返回值总是0呢?明明是存在&gt;50的人?<BR>请指教!谢谢了!
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:kf 回复日期:2003-08-05 15:58:13
<br>内容:use northwind <BR>go<BR>if exists (select name from sysobjects where name='exp_ret'<BR>and type='p')<BR>drop proc exp_ret<BR>go<BR>create proc exp_ret <BR>as <BR>if exists (select&nbsp;&nbsp;employeeid from employees<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where (2003 - year(birthdate)) &gt;=50)<BR>return (select count(distinct employeeid)from employees<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where (2003 - year(birthdate)) &gt;=50)<BR>else return 0<BR>go<BR>use northwind <BR>go<BR>declare @status int<BR>execute @status=exp_ret&nbsp;&nbsp;<BR>select 'procedure status'=@status<BR>go<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:xqq 回复日期:2003-08-06 14:12:19
<br>内容:请解释一下:为什么用return @@rowcount这个语句不能实现呢?<BR>谢谢!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:kf 回复日期:2003-08-06 14:37:48
<br>内容:@@rowcount参数好像是影响了多行的意思》<BR>你上面查询没有影响(没有改变)。<BR>所以不会返回出多少行来。<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -