create table A
(
a int,
b int
)想在A表中提取出前30条记录,插入到B表中(与A结构相同),
并且修改提取的记录的a字段,使a字段的值加1

解决方案 »

  1.   

    INSERT TB SELECT TOP 30 * FROM TA
    UPDATE TB SET A=A+1
      

  2.   

    create proc pr_test
    as
    begin
       select top 30 *  into # from a 
       insert into b select * from #
       update a
       set a = a+1
       where exists(select 1 from # where #.a = a.a and #.b = a.b)
       drop table #
    end
    go
      

  3.   


    iNSERT TB SELECT TOP 30 a+1,b FROM TA???
      

  4.   


    create proc pr_test
    as
    begin
       select top 30 *  into # from a 
       insert into b select * from #
       update a
       set a = a+1
       where exists(select 1 from # where #.a = a.a and #.b = a.b)
       drop table #
    end
    go