if object_id('dbo.Nums') is not null
drop table dbo.Nums
go
for
create table dbo.Nums(n int not null primary key);
declare @max as int,@rc as int;
set @max=1000000;
set @rc=1;
insert into Nums values(1);
while @rc*2<=@max
begin
insert into dbo.Nums
select n+@rc from dbo.Nums
set @rc=@rc*2;
end
insert into dbo.Nums
select n+@rc from dbo.Nums where n+@rc<=@max;
---select count(*) from nums
如上是为测试代码