create procedure P_BatchMove
@DE varchar(100),@so varchar(2000)
as
begin
declare
 @Sqlstr varchar(2000)
set @sqlstr = 'insert ' + @DE +  
               ' select s.*
               from (' + @so + ') as s  where not exist( select *  from ' + @de + ' d
                              where d.keycol = s.keycol)'
exec(@Sqlstr)
end方法大概就是这样了。没有测试,不敢保证正确

解决方案 »

  1.   

    BM是batchmove
    //
    set @sqlstr = 'insert ' + @DE +' select s.*from (' + @so + ') as s  where not exist( select *  from ' + @de + ' d where d.keycol = s.keycol)'
    这个是什么意思?
      

  2.   

    Create procedure BathchMoveProc
    as
    begin tran
      delete table1 where keycol in (select table2.keycol from table2 )
      insert into table1 select * from table2 
      if @@error != 0
      begin
        rollback tran
        --raiserror(90002,19,1) with log
        return(-1000)
      end
    commit tran
    return(0)
      

  3.   

    看你的意思,目的表和数据源都是动态的,要用动态SQL。
    那个就是要执行的Sql语句,用EXEC()执行。
    只是写了isnert,如果还有其他规则,比如update等,就用类似的方法写吧。忘了问是什么数据库,这个是MSSQL的语法。