Print 'Doing pre run Checks to ensure script not already run'; Select * from Script_History where Script_Name='QRSTocknotshowing'; 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 stock_item_id in ( select Stock_Item_ID from stock_item where item_stock_type_id in (1,3,2) and Stock_Item_ID in ( select stock_item_id from Stock_Item_Count where Stock_Holding_Group_ID in (1) and Stock_Count > 0)); end Print 'Insert into script history if everything else is cool'; Insert into Script_History (RunDate,Script_Name) Values (CURRENT_TIMESTAMP,'QRSTocknotshowing'); IF @@ERROR != 0 BEGIN RAISERROR ('UNABLE TO CONTINUE WITH SCRIPT', 11, 1); RETURN; END GO