Print 'Doing pre run Checks to ensure script not already run'; Select * from Script_History where Script_Name='FACGoodsReturnIssueFix'; 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 (3,6,17,24,25,26,35,41,67,70,76,82,86,93,100,111,121,129,142,146,149,155,156,158,162,165,174,182,183,186,199,219,246,276)) begin update Sales_Transaction_Line set Cost_Vat = (unit_cost * 1.15) - Unit_Cost where Sales_Transaction_ID in (select Sales_Transaction_ID from Sales_Transaction_Line where Cost_Vat is null and Sales_Transaction_ID in (select Sales_Transaction_ID from Sales_Transaction where created > '2023-10-01')) end Print 'Insert into script history if everything else is cool'; Insert into Script_History (RunDate,Script_Name) Values (CURRENT_TIMESTAMP,'FACGoodsReturnIssueFix'); IF @@ERROR != 0 BEGIN RAISERROR ('UNABLE TO CONTINUE WITH SCRIPT', 11, 1); RETURN; END GO