declare
   @EntityIdString VARCHAR(max)= '3928'
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

DECLARE @CustomerId bigint
SELECT @CustomerId = customerInformationId FROM customerinformation WHERE customername like '%Evangel Christian Center%'

DECLARE @TransactionsummaryId bigint
SELECT top 1 @TransactionsummaryId = oas.TransactionsummaryId 
FROM tbOnAccountSale oas with (nolock)
JOIN tbTransactionSummary ts with (nolock)
ON oas.transactionsummaryId = ts.TransactionsummaryId
WHERE oas.EntityId = @EntityId AND CustomerId = @CustomerId
AND ts.BusinessDay = '2020-1-15'

UPDATE tbOnAccountSale SET InvoiceNumber = '2772' , Description = 'Fall festival'
WHERE EntityId = @EntityId and CustomerId = @CustomerId and TransactionSummaryId = @TransactionsummaryId


END

FETCH NEXT FROM cur INTO @EntityId
END


CLOSE cur
DEALLOCATE cur