Print 'Doing pre run Checks to ensure script not already run'; Select * from Script_History where Script_Name='IphoneDiscCooStores03022025'; 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 (164,90,43,27,76,262,26,106,131,162,127,251,96,110,118,126)) begin insert into Product_Catalogue_History(Product_Catalogue_ID, Product_Catalogue_Status_ID, reason, MonthEnd) select pc.Product_Catalogue_ID, Last_Catalogue_Status_ID, 'Supplier Discontinued - Cooper take over', GETDATE() from Product_Catalogue pc where product_catalogue_id in ( select product_catalogue_id from product_catalogue where supplier_id = 1 and Product_Catalogue_Status_ID != 4 and product_id in ( select product_id from product where hq_product_id in (36257,36261,36263,36265,36267,36269,36399,36401,36509,36507,36493,36495,36497,36499,36501,36527,36529,40025,40027,40029,40031,40033,40035,40037,40039,40041,40891,42023,36519,36521,36523,36537,39189,40079,40081,40083,40085,40087,40089,40091,40093,40095,40491,36511,36513,36515,36517,36533,36593,38505,36535,36997,38585,38987,40113,40115,40117,40119,40121,40123,40125,40127,40129,40255,40485,36487,36489,36491,36591,37679,38903,36993,37249,37251,37259,37591,39175,42027,42029,36995,40043,40045,40047,40049,40051,40053,40055,40057,40059,40787,41433,42025,36503,36505,36531,36595,39069,42263,42285,42389,37221,41101,41103,41489,38301,38303,39635,41931,41985,41987,42091,38319,38325,42287,38637,41105,41937,41947,39779,40513,40515,42331,39819,40987,41491,40253,41615,42093,40899,40901,42035,42301,40993,42033,39613,41437,42031,41439,42295,38327,41107,42037 )) ); update Product_Catalogue set Product_Catalogue_Status_ID = 4, Last_Catalogue_Status_ID = Product_Catalogue_Status_ID, Last_Catalogue_Changed = GETDATE(), Last_Change_Reason = 'Supplier Discontinued - Cooper take over' where product_catalogue_id in ( select product_catalogue_id from product_catalogue where supplier_id = 1 and Product_Catalogue_Status_ID != 4 and product_id in ( select product_id from product where hq_product_id in (36257,36261,36263,36265,36267,36269,36399,36401,36509,36507,36493,36495,36497,36499,36501,36527,36529,40025,40027,40029,40031,40033,40035,40037,40039,40041,40891,42023,36519,36521,36523,36537,39189,40079,40081,40083,40085,40087,40089,40091,40093,40095,40491,36511,36513,36515,36517,36533,36593,38505,36535,36997,38585,38987,40113,40115,40117,40119,40121,40123,40125,40127,40129,40255,40485,36487,36489,36491,36591,37679,38903,36993,37249,37251,37259,37591,39175,42027,42029,36995,40043,40045,40047,40049,40051,40053,40055,40057,40059,40787,41433,42025,36503,36505,36531,36595,39069,42263,42285,42389,37221,41101,41103,41489,38301,38303,39635,41931,41985,41987,42091,38319,38325,42287,38637,41105,41937,41947,39779,40513,40515,42331,39819,40987,41491,40253,41615,42093,40899,40901,42035,42301,40993,42033,39613,41437,42031,41439,42295,38327,41107,42037 )) ); end Print 'Insert into script history if everything else is cool'; Insert into Script_History (RunDate,Script_Name) Values (CURRENT_TIMESTAMP,'IphoneDiscCooStores03022025'); IF @@ERROR != 0 BEGIN RAISERROR ('UNABLE TO CONTINUE WITH SCRIPT', 11, 1); RETURN; END GO