Print 'Doing pre run Checks to ensure script not already run'; Select * from Script_History where Script_Name='ProcFix11112024'; if @@ROWCOUNT!=0 BEGIN RAISERROR('THIS SCRIPT HAS ALREADY BEEN RUN ON THIS SERVER, CANNOT CONTINUE, PLEASE CONTACT DEV',11,1); RETURN; END GO IF (OBJECT_ID('UpdateIncentiveLastRun', 'P')) IS NOT NULL BEGIN DROP PROCEDURE [dbo].[UpdateIncentiveLastRun] END GO CREATE PROCEDURE [dbo].[UpdateIncentiveLastRun] @key varchar(100) AS BEGIN UPDATE SystemSetting SET SettingValueString = CONVERT(varchar, GETDATE(), 23) WHERE SettingKey = @key END GO IF (OBJECT_ID('AddAvailabilityStaging', 'P')) IS NOT NULL BEGIN DROP PROCEDURE [dbo].[AddAvailabilityStaging] END GO CREATE PROCEDURE [dbo].[AddAvailabilityStaging] -- Add the parameters for the stored procedure here @Division varchar(max), @Category varchar(max), @ProductCategoryType varchar(max), @Make varchar(max), @ModelCode varchar(150), @Description varchar(max), @Promo int, @UnitCost decimal(10, 2), @RRP decimal(10, 2), @GPPerc decimal(10, 2), @Last7DaysUnitSales decimal(10, 2), @Last14DaysUnitSales decimal(10, 2), @Last30DaysUnitSales decimal(10, 2), @Last7DaysRandSales decimal(10, 2), @Last14DaysRandSales decimal(10, 2), @Last30DaysRandSales decimal(10, 2), @Last7DaysGP decimal(10, 2), @Last14DaysGP decimal(10, 2), @Last30DaysGP decimal(10, 2), @StoreSOH int, @Par int, @OriginalPar int, @NoOfDaysOutOfStockLast7Days int, @NoOfDaysOutOfStockLast14Days int, @Last_Catalogue_Status_ID bigint, @Catalogue_Status_ID bigint, @ProductID bigint, @HQ_Product_ID bigint, @OnOrder int, @IsJV varchar(10), @SupplierID bigint, @TradingDayId bigint, @DaysSinceLastReceipted bigint AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here INSERT INTO AvailabilitiesStaging ( [Division] ,[Category] ,[ProductCategoryType] ,[Make] ,[ModelCode] ,[Description] ,[Promo] ,[UnitCost] ,[RRP] ,[GPPerc] ,[Last7DaysUnitSales] ,[Last14DaysUnitSales] ,[Last30DaysUnitSales] ,[Last7DaysRandSales] ,[Last14DaysRandSales] ,[Last30DaysRandSales] ,[Last7DaysGP] ,[Last14DaysGP] ,[Last30DaysGP] ,[StoreSOH] ,[Par] ,[OriginalPar] ,[NoOfDaysOutOfStockLast7Days] ,[NoOfDaysOutOfStockLast14Days] ,[Last_Catalogue_Status_ID] ,[Catalogue_Status_ID] ,[ProductID] ,[HQ_Product_ID] ,[OnOrder] ,[IsJV] ,[SupplierID] ,[TradingDayId] ,[DaysSinceLastReceipted]) VALUES ( @Division, @Category, @ProductCategoryType, @Make, @ModelCode, @Description, @Promo, @UnitCost, @RRP, @GPPerc, @Last7DaysUnitSales, @Last14DaysUnitSales, @Last30DaysUnitSales, @Last7DaysRandSales, @Last14DaysRandSales, @Last30DaysRandSales, @Last7DaysGP, @Last14DaysGP, @Last30DaysGP, @StoreSOH, @Par, @OriginalPar, @NoOfDaysOutOfStockLast7Days, @NoOfDaysOutOfStockLast14Days, @Last_Catalogue_Status_ID, @Catalogue_Status_ID, @ProductID, @HQ_Product_ID, @OnOrder, @IsJV, @SupplierID, @TradingDayId, @DaysSinceLastReceipted) END GO Print 'Insert into script history if everything else is cool'; Insert into Script_History (RunDate,Script_Name) Values (CURRENT_TIMESTAMP,'ProcFix11112024'); IF @@ERROR != 0 BEGIN RAISERROR ('UNABLE TO CONTINUE WITH SCRIPT', 11, 1); RETURN; END GO