把t1中的记录循环插入到t2,当其中某一条记录插入失败时,就记录下着条数据的标识,继续执行。就这样,当然可能会有n条错误的情况。急啊!

解决方案 »

  1.   


    declare @index int
    set @index=0while(@index < 21)
    BEGIN TRY
        -- Generate a divide-by-zero error.
        SELECT 1/0;
    END TRY
    BEGIN CATCH
        SELECT ERROR_LINE() AS ErrorLine;
    END CATCH;
         set @index = @index + 1
      

  2.   

    declare @index int
    set @index=0while(@index < 21)
    begin
    BEGIN TRY
        -- Generate a divide-by-zero error.
        SELECT 1/0;
    END TRY
    BEGIN CATCH
        SELECT ERROR_LINE() AS ErrorLine;
    END CATCH;set @index = @index + 1
    end
      

  3.   


    user tempdb
    go
    create table ta (id int identity(1,1) , sname uniqueidentifier)
    create table tb (id int ,sname uniqueidentifier)
    insert into ta values (newid())
    go 100declare @i int
    set @i=1
    while @i<=(select max(id) from ta   )
    begin
    begin tran
    insert into tb 
    select * from ta 
    where id =@i
    set @i=@i+1
    commit tran 
    if(@@error<>0)
    Rollback tran
    end