查询时加序号:
  a:没有主键的情形:
   Select identity(int,1,1) as iid,* into #tmp from TableName
   Select * from #tmp
   Drop table #tmp
  b:有主键的情形:
   Select (Select sum(1) from TableName where KeyField <= a.KeyField) as iid,* from TableName a

解决方案 »

  1.   

    本例:Select (Select sum(1) from TableName where id<= a.id) as 序号,* from TableName a
      

  2.   

    如何在结果集中加入行号
    Select identity(int,1,1) id,* into #tem from table1select * from #temdrop table #tem 
      

  3.   

    --改一下马可的
    --b:有主键的情形:
    Select (Select sum(1) from TableName where KeyField <= a.KeyField) as iid,* from TableName a order by  KeyField  --加上排序,不然这个序号很乱