вы можете сделать что-то подобное, чтобы перебрать каждую строку
declare @ii (id int) table
-- for batchchunk operations
declare @numTransactions as int = 0,
@totalRowsInserted as int = 0,
@chunksize int = 0,
@printnow varchar(1000)
--does the initial insert into the table
select * from #table
SET @numTransactions =@@rowcount
SET @printnow = 'Should Insert :'+cast(@numTransactions as varchar)+ ' rows into the table.'
exec db.printNow @printnow; -- shortened proc
BEGIN
INSERTCHUNKS:
SET ROWCOUNT @Batchsize
insert into table
(
type_id,
parent_id,
created_by_user_id,
created_at,
updated_by_user_id,
updated_at,
created_by_system_id,
updated_by_system_id,
is_deleted
)
output inserted.id into @ii(id)
select
1,--party_type_id
NULL,--parent_party_id
@user_id, --created_by_user_id
case when created_at is NULL then getdate() else created_at end ,
NULL , --updated_by_user_id
case when updated_at is NULL then getdate() else updated_at end, --
updated_at
case when created_by_system_id is null then 292 else 0 end, --created_by_system_id
updated_by_system_id,--updated_by_system_id \
0 --is_deleted
from
#table
order by id asc
OFFSET
@TotalRowsInserted ROWS
FETCH NEXT @batchsize ROWS ONLY
set @chunksize =@@rowcount
IF @chunksize > 0
BEGIN
set @totalRowsInserted = @totalRowsInserted + @chunksize
SET @printnow = 'Batch done: ' +
cast(@chunksize as varchar) + ' rows in Batch ; '
+ cast(@totalRowsInserted as varchar) + ' total inserted so far
into the table.' exec db.printnow @printnow;
waitfor delay '00:00:01'
GOTO INSERTCHUNKS
END
SET ROWCOUNT 0;
END