--方法1:
declare @i int=1,@sql nvarchar(1000);
while(@i<=23)
begin
set @sql =isnull(@sql+' union select ','select ')+cast(@i As nvarchar);
set @i=@i+1;
end
exec(@sql)
--方法2
SELECT number FROM MASTER..spt_values WHERE TYPE='P' and number>0 and number<24
--注视:spt_values是master数据库中的一张系统表,number的数值范围是0~2047
SqlServer中生成1~23之间的连续数字
最新推荐文章于 2024-02-02 10:56:18 发布