如何生成如下表格,谢谢比如以1000为标准分割100000想得结果
表1起       止
1       1000
1001   2000
2001   3000
3001   4000
4001   5000




98001   99000
98001   100000

解决方案 »

  1.   

    有什么要求么?
    一句SQL?存储过程?循环?还有你的版本是2000还是2005
      

  2.   

    declare @tb table(s int,e int)
    declare @s int,@e int
    select @s=1,@e=100000
    while @s<=@e
    begin
    insert into @tb select @s,@s+1000-1
    set @s=@s+1000
    endselect * from @tb
      

  3.   

    ;
    with cte as(
    select 1 as q,1000 as z
    union all
    select b.z+1 as q,b.z+1000 as z from cte b where b.z+1000<=100000
    )
    select * from cte
      

  4.   

    select top 100 id=identity(int,0,1) into # from sysobjects a,sysobjects b
    select id*1000+1 as q,(id+1)*1000 as z from #
    go
    drop table #