呵呵 select (100+number ) AS N from master..spt_values where type='p' and (100+number) between 100 and 123/*N ----------- 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123(所影响的行数为 24 行)*/
declare @i as int set @i=1 declare @s as varchar(20) while(@i<124) begin set @s=replace(str(@i,3),' ','0') print @s set @i=@i+1 end
看你的需求了 int类型还有个最大最小值呢
有没有比这个更快的方法了?declare @s int declare @e int declare @q varchar(150)set @s=10 set @e=20000select 0 as 'a' into #t1 while @s<=@e begin insert #t1 (a) values (@s) set @s=@s+1 endselect 'XXA'+cast(a as varchar),'aa' from #t1drop table #t1
就是不知道范围是多少。不过肯定是在int之内的。总不能把所有的int都存进去吧。
create table tb(n int) godeclare @i int declare @n intselect @i=1 select @n=@iinsert into tb values(1)while @n*2<=2000 begin insert into tb(n) select @n+n from tb select @n=@n*2 end insert into tb(n) select @n+n from tb where @n+n<=2000select * from tb--drop table tb这个稍微好点 哈哈
select identity(int,1,1) as n into # from syscolumns a,syscolumns bselect * from #
用 Top (123-100) 控制精度 select top 23 identity(int,1,1) as n into # from syscolumns a,syscolumns b然后用 起始数 100 select 100+n from #
可以用between 100 and 100000000
drop table # select identity(int,1,1) as n into # from syscolumns a,syscolumns b select * from # where n between 100 and 10000000 order by n结果: 178084 100并不是10000000
打错了 drop table # select identity(int,1,1) as n into # from syscolumns a,syscolumns b select max(n),min(n) from # where n between 100 and 10000000
select max(n),min(n) from # where n between 100 and 10000000 -- ----------- ----------- 10000000 100(所影响的行数为 1 行)
from master..spt_values
where type='p' and (100+number) between 100 and 123/*N
-----------
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123(所影响的行数为 24 行)*/
set @i=1
declare @s as varchar(20)
while(@i<124)
begin
set @s=replace(str(@i,3),' ','0')
print @s
set @i=@i+1
end
declare @e int
declare @q varchar(150)set @s=10
set @e=20000select 0 as 'a' into #t1
while @s<=@e
begin
insert #t1 (a) values (@s)
set @s=@s+1
endselect 'XXA'+cast(a as varchar),'aa' from #t1drop table #t1
godeclare @i int
declare @n intselect @i=1
select @n=@iinsert into tb values(1)while @n*2<=2000
begin
insert into tb(n)
select @n+n from tb
select @n=@n*2
end insert into tb(n)
select @n+n from tb where @n+n<=2000select * from tb--drop table tb这个稍微好点 哈哈
select top 23 identity(int,1,1) as n into # from syscolumns a,syscolumns b然后用 起始数 100 select 100+n from #
select identity(int,1,1) as n into # from syscolumns a,syscolumns b select * from # where n between 100 and 10000000 order by n结果:
178084 100并不是10000000
drop table #
select identity(int,1,1) as n into # from syscolumns a,syscolumns b select max(n),min(n) from # where n between 100 and 10000000
--
----------- -----------
10000000 100(所影响的行数为 1 行)
这个表中的number是不确定的