select idrow=identity(int,1,1) ,......
int0 #
from table,.....
where .......select * from #drop table #

解决方案 »

  1.   

    select IDENTITY(int) , *
    into #tmp
    from testselect * from #tmpdrop table #tmp
      

  2.   

    --临时表比较简单--还有通过关键字可以加序号的类似如下方法:select 序号=(select sum(1) from 表 where 主键<=A.主键),* from 表 A
      

  3.   

    谢谢楼上三位大哥,但是都不对呀我要的是在我的查询出来的结果中插入一列
    a,5,5
    b,5,5
    c,5,5
    ====>
    1,a,5,5
    2,b,5,5
    3,c,5,5没分了,谢谢各位大哥先
      

  4.   

    declare @t table(a varchar(20))
    insert @t 
    select 'a,5,5' union all
    select 'b,5,5' union all
    select 'c,5,5'declare @I int
    set @I =0update @t set a = convert(varchar(2),@i)+','+a ,@i =@i +1select * from @t/*a                    
    -------------------- 
    1,a,5,5
    2,b,5,5
    3,c,5,5
    */
      

  5.   

    declare @t table(col1 varchar(10),col2 int,col3 int)
    insert into @t select 'a',5,5
    union all select 'b',5,5
    union all select 'c',5,5select 
       序号=(select sum(1) from @t where col1<=A.col1),
       *
    from @t A--严格一点
    select 
       序号=(select sum(1) from @t where col1+'_'+cast(col2 as varchar)+'_'+cast(col3 as varchar)<=A.col1+'_'+cast(A.col2 as varchar)+'_'+cast(A.col3 as varchar)),
       *
    from @t A序号          col1       col2        col3        
    ----------- ---------- ----------- ----------- 
    1           a          5           5
    2           b          5           5
    3           c          5           5(所影响的行数为 3 行)序号          col1       col2        col3        
    ----------- ---------- ----------- ----------- 
    1           a          5           5
    2           b          5           5
    3           c          5           5(所影响的行数为 3 行)
    --关键找准你表的主键字段。