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

--insert
IF EXISTS (SELECT TOP 1 * FROM tbRebankTransaction WITH (NOLOCK))
BEGIN

DECLARE @pageInsert INT = 0
DECLARE @lastCountInsert INT = 1

WHILE @lastCountInsert > 0
BEGIN

	BEGIN TRANSACTION

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

	COMMIT TRANSACTION

END
END

--delete
IF EXISTS (SELECT 1 FROM tbRebankTransaction)
BEGIN

DECLARE @lastCountDelete INT = 1

WHILE @lastCountDelete > 0
BEGIN

	BEGIN TRANSACTION

		DELETE TOP (@batchDelete)
		FROM  tbRebankTransaction

		SET @lastCountDelete = @@ROWCOUNT

	COMMIT TRANSACTION

END
END