DECLARE @batchInsert INT = 100000;
DECLARE @batchDelete INT = 100000;

--insert
IF EXISTS (SELECT TOP 1 * FROM tbBankingTransaction WHERE [Type] = 'Rebank')
BEGIN

DECLARE @page INT = 0
DECLARE @lastCount INT = 1

WHILE @lastCount > 0
BEGIN

	BEGIN TRANSACTION

		INSERT into tbRebankTransaction
		SELECT [BankingID]
			  ,[TransactionDate]
			  ,[PeriodNo]
			  ,[FiscalYear]
			  ,[ClerkName]
			  ,[ManagerName]
			  ,[ExpectedDeposit]
			  ,[AmountConfirmed]
			  ,[ActualDeposit]
			  ,[EntityID]
			  ,[BankingFloatCountID]
			  ,[BusinessDay]
		FROM    ( SELECT    ROW_NUMBER() OVER ( ORDER BY BankingTransactionID ) AS RowNum, 
				  [BankingID]
				  ,[TransactionDate]
				  ,[PeriodNo]
				  ,[FiscalYear]
				  ,[ClerkName]
				  ,[ManagerName]
				  ,[ExpectedDeposit]
				  ,[AmountConfirmed]
				  ,[ActualDeposit]
				  ,[EntityID]
				  ,[BankingFloatCountID]
				  ,[BusinessDay]
				  FROM      tbBankingTransaction WITH (NOLOCK)
				  WHERE [Type] = 'Rebank'
				) AS RowConstrainedResult
		WHERE   RowNum >= (@page * @batchInsert) AND RowNum < ((@page+1) * @batchInsert)
		SET @lastCount = @@ROWCOUNT
		SET @page = @page + 1

	COMMIT TRANSACTION

END
END

--delete
IF EXISTS (SELECT 1 FROM tbBankingTransaction WHERE [Type] = 'Rebank')
BEGIN

DECLARE @lastCountDelete INT = 1

WHILE @lastCountDelete > 0
BEGIN

	BEGIN TRANSACTION

		DELETE TOP (@batchDelete)
		FROM  tbBankingTransaction
		WHERE [Type] = 'Rebank'

		SET @lastCountDelete = @@ROWCOUNT

	COMMIT TRANSACTION

END
END