如何在sqlsever2008中使用存储过程显示1到100个数字 [英] how to display 1 to 100 numbers by using store procedures in sqlsever2008

查看:98
本文介绍了如何在sqlsever2008中使用存储过程显示1到100个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用sqlsever2008中的存储过程编写显示1到100个数字的命令.

how to write command to display 1 to 100 numbers by using store procedures in sqlsever2008,.

推荐答案

hi ..

这是3个示例,您可以根据需要进行选择..第1个打印1-100,然后选择以逗号分隔的内容,第3个以表格形式访问

复制此代码并在sql中运行,您将得到它

hi ..

here is 3 sample you can you what your need .. 1st to print 1-100 and next to select as comma seperated and 3 rd to access like a table

copy this code and run it in sql you will get it

declare @strOUT varchar(5000)
declare @cnt int
set @cnt=0
set @strOUT=''''
while @cnt<100
begin  
set @cnt=@cnt+1
print @cnt
end 







declare @strOUT varchar(5000)
declare @cnt int
set @cnt=0
set @strOUT=''''
while @cnt<100
begin  
set @cnt=@cnt+1
set @strOUT =@strOUT +'',''+ cast(@cnt as varchar)
print @cnt
end 
select @strOUT







Declare @TempTableOut Table (cnt int)  
declare @strOUT varchar(5000)
declare @cnt int
set @cnt=0
set @strOUT=''''
while @cnt<100
begin  
set @cnt=@cnt+1
insert into @TempTableOut values(@cnt)
end 
select * from @TempTableOut




希望对您有帮助




hope this will help you


这篇关于如何在sqlsever2008中使用存储过程显示1到100个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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