Print 'Doing pre run Checks to ensure script not already run'; Select * from Script_History where Script_Name='LaybyOrders10072025'; 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 (13, 26, 49, 64, 65, 73, 90, 91, 98, 140, 145, 154, 163, 207, 241, 255, 258, 298, 311, 312, 313 )) begin Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 236475 and @StoreId =13; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=236475 and @StoreId=13; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 5744 and @StoreId =26; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=5744 and @StoreId=26; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 239072 and @StoreId =49; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=239072 and @StoreId=49; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 283498 and @StoreId =64; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=283498 and @StoreId=64; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 135692 and @StoreId =65; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=135692 and @StoreId=65; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 87259 and @StoreId =73; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=87259 and @StoreId=73; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 87284 and @StoreId =73; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=87284 and @StoreId=73; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 87293 and @StoreId =73; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=87293 and @StoreId=73; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 5432 and @StoreId =90; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=5432 and @StoreId=90; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 30705 and @StoreId =91; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=30705 and @StoreId=91; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 56312 and @StoreId =98; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=56312 and @StoreId=98; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 56315 and @StoreId =98; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=56315 and @StoreId=98; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 94481 and @StoreId =140; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=94481 and @StoreId=140; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 94483 and @StoreId =140; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=94483 and @StoreId=140; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 35194 and @StoreId =145; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=35194 and @StoreId=145; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 187577 and @StoreId =154; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=187577 and @StoreId=154; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 165956 and @StoreId =163; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=165956 and @StoreId=163; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 94029 and @StoreId =207; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=94029 and @StoreId=207; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 333294 and @StoreId =241; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=333294 and @StoreId=241; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 333298 and @StoreId =241; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=333298 and @StoreId=241; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 50625 and @StoreId =255; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=50625 and @StoreId=255; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 330423 and @StoreId =258; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=330423 and @StoreId=258; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 307 and @StoreId =298; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=307 and @StoreId=298; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 88 and @StoreId =311; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=88 and @StoreId=311; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 93 and @StoreId =311; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=93 and @StoreId=311; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 147 and @StoreId =312; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=147 and @StoreId=312; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 151 and @StoreId =312; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=151 and @StoreId=312; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 165 and @StoreId =312; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=165 and @StoreId=312; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 93 and @StoreId =313; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=93 and @StoreId=313; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 95 and @StoreId =313; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=95 and @StoreId=313; Update Lay_bye set laybystockstatusid = 1 where lay_bye_id = 101 and @StoreId =313; update purchase_order set purchase_order_status_id =1, sent_to_supplier = null where laybyid=101 and @StoreId=313; end; Print 'Insert into script history if everything else is cool'; Insert into Script_History (RunDate,Script_Name) Values (CURRENT_TIMESTAMP,'LaybyOrders10072025'); IF @@ERROR != 0 BEGIN RAISERROR ('UNABLE TO CONTINUE WITH SCRIPT', 11, 1); RETURN; END GO