求一句SQL语句,能够生成1列31行的数据,列为1到31的序号
也就是生成如下形式
序号
1
2
3
...
中间省略
...
30
31

解决方案 »

  1.   


    --用临时表select top 31 identity(int,1,1) as ID
    into #tp
    from syscolumns c1,syscolumns c2 
    select * from #tpdrop table #tp
      

  2.   

    select top 31 identity(int,1,1)TID into #t from sysobjectsselect * from #t
      

  3.   

    declare @t table(id int)
    declare @i int
    set @i=1
    while @i<=31
    begin
      insert into @t select @i
      set @i=@i+1
    endselect * from @tid          
    ----------- 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31(所影响的行数为 31 行)
      

  4.   

    select top 31 identity(int,1,1)TID into #s from sysobjectsselect * from #s
    drop table #s