Print 'Doing pre run Checks to ensure script not already run'; Select * from Script_History where Script_Name='FACSSBAdminIssueFix'; if @@ROWCOUNT!=0 BEGIN RAISERROR('THIS SCRIPT HAS ALREADY BEEN RUN ON THIS SERVER, CANNOT CONTINUE, PLEASE CONTACT DEV',11,1); RETURN; END GO declare @StoreId int; set @StoreId = (select default_value from system_default where Default_Name = 'Main_store_id'); If(@StoreId in (2,3,6,17,24,25,26,27,38,41,50,54,62,67,68,69,70,75,76,82,85,86,90,93,96,100,106,110,111,113,118,121,124,126,127,128,129,131,135,142,146,149,150,155,156,158,162,164,165,173,174,177,182,183,185,199,215,219,220,227,242,246,251,262,276)) begin update ssb set AdminFeeAmount = (Secured_Amount * 0.33) - (InitiationFee + Interest_Amount), AdminFeeVat = ((Secured_Amount * 0.33) - (InitiationFee + Interest_Amount)) - (((Secured_Amount * 0.33) - (InitiationFee + Interest_Amount))/1.15) where CreationDate > '2023-11-16' and (InitiationFee + Interest_Amount + AdminFeeAmount) > (Secured_Amount * 0.33); update ssb set ContractNumber = CONCAT(ContractNumber,SSB_ID) where CreationDate > '2023-11-16' and ContractNumber in (select ContractNumber from ( select contractnumber,count(0) as Countcontract from ssb where CreationDate > '2023-11-16' group by ContractNumber) a where a.Countcontract >1); end Print 'Insert into script history if everything else is cool'; Insert into Script_History (RunDate,Script_Name) Values (CURRENT_TIMESTAMP,'FACSSBAdminIssueFix'); IF @@ERROR != 0 BEGIN RAISERROR ('UNABLE TO CONTINUE WITH SCRIPT', 11, 1); RETURN; END GO