存储过程简单问题 [英] storedprocedure simple question

查看:61
本文介绍了存储过程简单问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存储过程中如何打印1到100个数字

in storedprocedure how to print 1 to 100 numbers

推荐答案

SQL Server:

您真的要打印" 100个数字吗?还是要返回结果集?

-仅打印.
创建过程print100
AS
开始
声明@seqno int;
设置@ seqno = 0;
虽然(@seqno< 100)
开始
设置@seqno = @seqno + 1;
打印演员表(@seqno as varchar(8));
结束
结束
go
SQL Server:

Do you really want to "PRINT" 100 numbers? Or do you want to return a result set?

-- Printing only.
create procedure print100
AS
begin
declare @seqno int;
set @seqno=0;
While (@seqno < 100)
begin
set @seqno = @seqno + 1;
print cast(@seqno as varchar(8));
end
end
go


您无法在存储的过程中打印任何内容.您可以选择一个静态序列并根据需要返回它.您也许应该更清楚自己想做什么.

选择1,2,3,4,5,... 100将返回这些数字.您也许也可以使用较短的语法来做到这一点.
You can''t print anything in a stored proc. You can select a static sequence and return it if you want to. You should perhaps be more clear what you''re hoping to do.

select 1,2,3,4,5,...100 will return those numbers. You may be able to do it in a shorter syntax, too.


这篇关于存储过程简单问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆