Print 'Doing pre run Checks to ensure script not already run'; Select * from Script_History where Script_Name='FACOrigPurchaseDateFix28112024'; 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 Stock_Item set Original_Purchase_Date = (select created from Buyshop_Transaction where Buyshop_Transaction_ID = (select Buyshop_Transaction_id from Buyshop_Trans_Line btl where btl.Buyshop_Trans_Line_ID = stock_item.Buyshop_Trans_Line_ID) ) where item_stock_type_id in (1,3,2,7) and Original_Purchase_Date is null; update stock_item set Original_Purchase_Date = (select top 1 authorised_date from Stock_Receipt_Line srl left join Stock_Receipt sr on sr.Stock_Receipt_ID = srl.Stock_Receipt_ID where srl.Stock_Item_ID = Stock_Item.Stock_Item_ID and Stock_Receipt_Status_ID = 2 order by Authorised_Date desc) where Item_Stock_Type_ID in (4,8) and Original_Purchase_Date is null; update stock_item set Original_Purchase_Date = '2024-11-01' where Original_Purchase_Date is null; end If(@StoreId in (150, 146)) begin UPDATE systemsetting SET settingvaluebit=1 WHERE settingkey = 'PromoAutomationActivated'; end If(@StoreId in (26,27,43,71,76,90,96,106,107,110,115,118,126,127,128,131,151,162,164,171,242,251,262)) begin UPDATE promotion set period_start = '2024-11-29', period_end = '2024-12-01', lockdowndate = '2024-11-11' where promotion_id = 283; end Print 'Insert into script history if everything else is cool'; Insert into Script_History (RunDate,Script_Name) Values (CURRENT_TIMESTAMP,'FACOrigPurchaseDateFix28112024'); IF @@ERROR != 0 BEGIN RAISERROR ('UNABLE TO CONTINUE WITH SCRIPT', 11, 1); RETURN; END GO