declare
  @EntityIdString VARCHAR(max)= '123, 678'  

 
 DECLARE @EntityId bigint
 
 DECLARE cur CURSOR FOR SELECT value from dbo.fn_Split(@EntityIdString,',')
 OPEN cur
 
 FETCH NEXT FROM cur INTO @EntityId
 
 WHILE @@FETCH_STATUS = 0 
 
BEGIN  

if exists (select * from tbEntity with (nolock) where EntityID = @EntityId)

BEGIN

update tbTransactionSummary set Rounding = 0.03 where EntityID = 4203 and BusinessDay = '2015-1-14' and ClerkID = 1355870 and POSTransactionID = 1336787 and TransactionVersion = 0
update tbTransactionSummary set Rounding = -0.01 where EntityID =4203 and BusinessDay = '2015-1-14' and ClerkID = 1234687 and POSTransactionID = 1337813 and TransactionVersion = 0
declare @transactioncashdepositId1 as bigint
declare @transactioncashdepositId2 as bigint

select top 1 @transactioncashdepositId1 = TransactionCashDepositID from tbTransactionCashDeposit with (nolock) where EntityID =@EntityId and CashDepositDate = '2015-1-14' and ClerkName = 'Shapiro, Yehoshua' and RegisterSales <> 0

select top 1 @transactioncashdepositId2 = TransactionCashDepositID from tbTransactionCashDeposit with (nolock) where EntityID =@EntityId and CashDepositDate = '2015-1-14' and ClerkName = 'Lopez, Anna' and RegisterSales <> 0

insert into tbTransactionCashDepositFinancial(TransactionCashDepositID, FinancialGroupID, Amount, Quantity, AmountPolled, QuantityPolled)
values(@transactioncashdepositId1, 143, 0.03, 1, 0.03,1)

insert into tbTransactionCashDepositFinancial(TransactionCashDepositID, FinancialGroupID, Amount, Quantity, AmountPolled, QuantityPolled)
values(@transactioncashdepositId2, 143, -0.01, 1, -0.01,1)

END

FETCH NEXT FROM cur INTO @EntityId
END


CLOSE cur    
DEALLOCATE cur


