表source中有开始编号和结束编号两个字段,
如: 
       .., 开始编号, 结束编号,...
记录i:..,100000023,100000027,...
此记录中想获取的编号为:100000023,100000024,100000025,100000026,100000027.如何将表source中的所有编号全部取出来,放入新表中?
   

解决方案 »

  1.   

    declare @i int
    set @I = 100000023
    while @i <= 100000027
    begin 
       insert into ta select @i
       set @i = @I + 1
    end
      

  2.   

    --> 测试数据: #T
    if object_id('tempdb.dbo.#T') is not null drop table #T
    create table #T (n1 int,n2 int)
    insert into #T
    select 100000023,100000027 union all
    select 100000030,100000031select top 100 num=identity(int,0,1) into # from syscolumnsselect n1+num as num from #T a, # b where num+n1 between n1 and n2/*
    num
    -----------
    100000023
    100000024
    100000025
    100000026
    100000027
    100000030
    100000031
    */