insert into a(name,storeid)
select name ,XXX
from b如果b中有有5条数据,xxx 为1,2,3,4,5就相当于判断当前是第几行,怎么实现用sql 

解决方案 »

  1.   

    insert into a(name,storeid)
    select name ,XXX=row_number() over(order by name)
    from b
      

  2.   

    用游標新增,或在新增前 在alter table b add ID int identity--新增標識列
      

  3.   


    SELECT name,IDENTITY(1,1)AS ID INTO TB FROM Binsert into a(name,storeid) 
    select name ,ID from TB DROP TABLE TB
      

  4.   


    if object_id('tempdb..#t') is not null
      drop table #tSELECT IDENTITY(int,1,1) as XXXX ,name INTO #t FROM bINSERT INTO a SELECT name,XXXX FROM #t ORDER BY XXXX