Author |
Topic |
Arunraj
Starting Member
18 Posts |
Posted - 2015-03-06 : 05:19:10
|
Hi friends,I have stored procedure .In SP i am using cursur to load data from Parent to several child table.I have attached the script with this message.And my problem is how to use direct select and insert or load to speedup the process instead of cursur.Can any one please suggest me how to change this scripts pls.USE [IconicMarketing]GO/****** Object: StoredProcedure [dbo].[SP_DMS_INVENTORY] Script Date: 3/6/2015 3:34:03 PM ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author: <ARUN,NAGARAJ>-- Create date: <11/21/2014>-- Description: <STORED PROCEDURE FOR DMS_INVENTORY>-- =============================================ALTER PROCEDURE [dbo].[SP_DMS_INVENTORY] @Specific_Date varchar(20) , @DealerNum Varchar(6), @Date_Daily varchar(50)ASBEGIN SET NOCOUNT ON;--==========================================================================-- INVENTORY_CURSUR --==========================================================================DECLARE @FileType varchar(50), @ACDealerID varchar(50), @ClientDealerID varchar(50), @DMSType varchar(50), @StockNumber varchar(50), @InventoryDate datetime , @StockType varchar(100), @DMSStatus varchar(50), @InvoicePrice numeric(18, 2), @CostPack varchar(50), @SalesCost numeric(18, 2), @HoldbackAmount numeric(18, 2), @ListPrice numeric(18, 2), @MSRP varchar(max), @LotLocation varchar(50), @TagLine varchar(max), @Certification varchar(max), @CertificationNumber varchar(max), @VehicleVIN varchar(50), @VehicleYear bigint , @VehicleMake varchar(50), @VehicleModel varchar(50), @VehicleModelCode varchar(50), @VehicleTrim varchar(50), @VehicleSubTrimLevel varchar(max), @Classification varchar(max), @TypeCode varchar(100), @VehicleMileage bigint , @EngineCylinderCount varchar(10) , @TransmissionType varchar(50), @VehicleExteriorColor varchar(50), @VehicleInteriorColor varchar(50), @CreatedDate datetime , @LastModifiedDate datetime , @ModifiedFlag varchar(max), @InteriorColorCode varchar(50), @ExteriorColorCode varchar(50), @PackageCode varchar(50), @CodedCost varchar(50), @Air varchar(100), @OrderType varchar(max), @AgeDays bigint , @OutstandingRO varchar(50), @DlrAccessoryRetail varchar(50), @DlrAccessoryCost varchar(max), @DlrAccessoryDesc varchar(max), @ModelDesc varchar(50), @Memo1 varchar(1000), @Memo2 varchar(max), @Weight varchar(max), @FloorPlan numeric(18, 2), @Purchaser varchar(max), @PurchasedFrom varchar(max), @InternetPrice varchar(50), @InventoryAcctDollar numeric(18, 2), @VehicleType varchar(50), @DealerAccessoryCode varchar(50), @AllInventoryAcctDollar numeric(18, 2), @BestPrice varchar(50), @InStock bigint , @AccountingMake varchar(50), @GasDiesel varchar(max), @BookValue varchar(10), @FactoryAccessoryDescription varchar(max), @TotalReturn varchar(10), @TotalCost varchar(10), @SS varchar(max), @VehicleBody varchar(max), @StandardEquipment varchar(max), @Account varchar(max), @CalculatedPrice varchar(10), @OriginalCost varchar(10), @AccessoryCore varchar(10), @OtherDollar varchar(10), @PrimaryBookValue varchar(10), @AmountDue varchar(10), @LicenseFee varchar(10), @ICompany varchar(max), @InvenAcct varchar(max), @Field23 varchar(max), @Field24 varchar(max), @SalesCode bigint, @BaseRetail varchar(10), @BaseInvAmt varchar(10), @CommPrice varchar(10), @Price1 varchar(10), @Price2 varchar(10), @StickerPrice varchar(10), @TotInvAmt varchar(10), @OptRetail varchar(max), @OptInvAmt varchar(10), @OptCost varchar(10), @Options1 varchar(max), @Category varchar(max), @Description varchar(max), @Engine varchar(max), @ModelType varchar(max), @FTCode varchar(max), @Wholesale varchar(max), @Retail varchar(max), @Draft varchar(max), @myerror varchar(500), @Inventoryid int, @errornumber int, @errorseverity varchar(500), @errortable varchar(50), @errorstate int, @errorprocedure varchar(500), @errorline varchar(50), @errormessage varchar(1000), @Invt_Id int, @flatfile_createddate datetime, @FtpDate date, @Inv_cur varchar(1000), @S_Year varchar(4), @S_Month varchar(2), @S_Date varchar(2), @Date_Specfic varchar(50), @Param_list nvarchar(max), @Daily_Date Varchar(50);--====================================================================================--DECLARE CURSUR FOR SPECIFIC DATE (OR) DEALER-ID WITH SPECIFIC DATE (OR) CURRENT DATE --====================================================================================set @Date_Specfic = Substring(@Specific_Date,1,4) +'-'+Substring(@Specific_Date,5,2)+'-'+Substring(@Specific_Date,7,2);set @Daily_Date = SUBSTRING(@Date_Daily,14,4) + '-' + SUBSTRING(@Date_Daily,18,2)+ '-' + SUBSTRING(@date_Daily,20,2)IF @Daily_Date IS NOT NULL BEGIN Delete From [dbo].[DMS_INVENTORY_DETAILS] Where DMSInventoryID in(select ID from [dbo].[DMS_INVENTORY] where CONVERT (date,FtpDate)=CONVERT (date,GETDATE())); Delete From [dbo].[DMS_INVENTORY_AMOUNT] Where DMSInventoryID in(select ID from [dbo].[DMS_INVENTORY] where CONVERT (date,FtpDate)=CONVERT (date,GETDATE())); Delete From [dbo].[ICONIC_INVENTORY_VEHICLE] Where DMSInventoryVehicleID in(select ID from [dbo].[DMS_INVENTORY] where CONVERT (date,FtpDate)=CONVERT (date,GETDATE())); Delete From [dbo].[DMS_INVENTORY_VEHICLE] Where DMSInventoryID in(select ID from [dbo].[DMS_INVENTORY] where CONVERT (date,FtpDate)=CONVERT (date,GETDATE())); Delete From [dbo].[ICONIC_EQUITY_INVENTORY_COMPARE] Where InventoryVehicleId in(select ID from [dbo].[DMS_INVENTORY] where CONVERT (date,FtpDate)=CONVERT (date,GETDATE())); Delete From [dbo].[DMS_INVENTORY] Where ID in(select ID from [dbo].[DMS_INVENTORY] where CONVERT (date,FtpDate)=CONVERT (date,GETDATE())); DECLARE Inventory_Cursor CURSOR FOR SELECT * from [dbo].[FLATFILE_INVENTORY] where CONVERT (date,flatfile_createddate) = CONVERT (date,GETDATE()) order by flatfile_createddate; ENDElse BEGIN if (@Date_Specfic IS NOT NULL AND @DealerNum != '?????') BEGIN Delete From [dbo].[DMS_INVENTORY_DETAILS] Where DMSInventoryID in(select ID from [dbo].[DMS_INVENTORY] where FtpDate=@Date_Specfic AND DMSDealerID='ACTEST' + @DealerNum); Delete From [dbo].[DMS_INVENTORY_AMOUNT] Where DMSInventoryID in(select ID from [dbo].[DMS_INVENTORY] where FtpDate=@Date_Specfic AND DMSDealerID='ACTEST' + @DealerNum); Delete From [dbo].[ICONIC_INVENTORY_VEHICLE] Where DMSInventoryVehicleID in(select ID from [dbo].[DMS_INVENTORY] where FtpDate=@Date_Specfic AND DMSDealerID='ACTEST' + @DealerNum); Delete From [dbo].[DMS_INVENTORY_VEHICLE] Where DMSInventoryID in(select ID from [dbo].[DMS_INVENTORY] where FtpDate=@Date_Specfic AND DMSDealerID='ACTEST' + @DealerNum); Delete From [dbo].[ICONIC_EQUITY_INVENTORY_COMPARE] Where InventoryVehicleId in(select ID from [dbo].[DMS_INVENTORY] where FtpDate=@Date_Specfic AND DMSDealerID='ACTEST' + @DealerNum); Delete From [dbo].[DMS_INVENTORY] Where ID in(select ID from [dbo].[DMS_INVENTORY] where FtpDate=@Date_Specfic AND DMSDealerID='ACTEST' + @DealerNum); DECLARE Inventory_Cursor CURSOR FOR SELECT * from [dbo].[FLATFILE_INVENTORY] where FtpDate=@Date_Specfic AND ACDealerID='ACTEST' + @DealerNum; END ELSE BEGIN Delete From [dbo].[DMS_INVENTORY_DETAILS] Where DMSInventoryID in(select ID from [dbo].[DMS_INVENTORY] where FtpDate=@Date_Specfic); Delete From [dbo].[DMS_INVENTORY_AMOUNT] Where DMSInventoryID in(select ID from [dbo].[DMS_INVENTORY] where FtpDate=@Date_Specfic); Delete From [dbo].[ICONIC_INVENTORY_VEHICLE] Where DMSInventoryVehicleID in(select ID from [dbo].[DMS_INVENTORY] where FtpDate=@Date_Specfic); Delete From [dbo].[DMS_INVENTORY_VEHICLE] Where DMSInventoryID in(select ID from [dbo].[DMS_INVENTORY] where FtpDate=@Date_Specfic); Delete From [dbo].[ICONIC_EQUITY_INVENTORY_COMPARE] Where InventoryVehicleId in(select ID from [dbo].[DMS_INVENTORY] where FtpDate=@Date_Specfic); Delete From [dbo].[DMS_INVENTORY] Where ID in(select ID from [dbo].[DMS_INVENTORY] where FtpDate=@Date_Specfic); DECLARE Inventory_Cursor CURSOR FOR SELECT * from [dbo].[FLATFILE_INVENTORY] where FtpDate=@Date_Specfic; END END OPEN Inventory_Cursor FETCH NEXT FROM Inventory_Cursor INTO @FileType , @ACDealerID , @ClientDealerID , @DMSType , @StockNumber , @InventoryDate , @StockType , @DMSStatus , @InvoicePrice , @CostPack , @SalesCost , @HoldbackAmount , @ListPrice , @MSRP , @LotLocation , @TagLine , @Certification , @CertificationNumber , @VehicleVIN , @VehicleYear , @VehicleMake , @VehicleModel , @VehicleModelCode , @VehicleTrim , @VehicleSubTrimLevel , @Classification , @TypeCode , @VehicleMileage , @EngineCylinderCount , @TransmissionType , @VehicleExteriorColor , @VehicleInteriorColor , @CreatedDate , @LastModifiedDate , @ModifiedFlag , @InteriorColorCode , @ExteriorColorCode , @PackageCode , @CodedCost , @Air , @OrderType , @AgeDays , @OutstandingRO , @DlrAccessoryRetail , @DlrAccessoryCost , @DlrAccessoryDesc , @ModelDesc , @Memo1 , @Memo2 , @Weight , @FloorPlan , @Purchaser , @PurchasedFrom , @InternetPrice , @InventoryAcctDollar , @VehicleType , @DealerAccessoryCode , @AllInventoryAcctDollar , @BestPrice , @InStock , @AccountingMake , @GasDiesel , @BookValue , @FactoryAccessoryDescription , @TotalReturn , @TotalCost , @SS , @VehicleBody , @StandardEquipment , @Account , @CalculatedPrice , @OriginalCost , @AccessoryCore , @OtherDollar , @PrimaryBookValue , @AmountDue , @LicenseFee , @ICompany , @InvenAcct , @Field23 , @Field24 , @SalesCode , @BaseRetail , @BaseInvAmt , @CommPrice , @Price1 , @Price2 , @StickerPrice , @TotInvAmt , @OptRetail , @OptInvAmt , @OptCost , @Options1 , @Category , @Description , @Engine , @ModelType , @FTCode , @Wholesale , @Retail , @Draft , @flatfile_createddate, @FtpDate; WHILE @@FETCH_STATUS = 0BEGIN --==========================================================================-- INSERT INTO INVENTORY (PARENT TABLE) --==========================================================================BEGIN TRYINSERT INTO [dbo].[DMS_INVENTORY] ( DMSDealerID, StockNumber, DMSType, InventoryDate, FtpDate ) VALUES (@ClientDealerID,@StockNumber,@DMSType,@InventoryDate,@FtpDate);END TRY BEGIN CATCHSELECT @errornumber = ERROR_NUMBER(), @errorseverity = ERROR_SEVERITY(), @errortable = 'DMS_INVENTORY', @errorstate = ERROR_STATE(), @errorprocedure = ERROR_PROCEDURE(), @errorline = ERROR_LINE(), @errormessage = ERROR_MESSAGE();--==========================================================================-- INSERT ERRORS INTO DMSLOG_INVENTORY_ERROR--==========================================================================EXEC [SP_DMS_INVENTORY_ERROR] @FileType,@ACDealerID,@ClientDealerID,@DMSType,@StockNumber,@InventoryDate,@StockType,@DMSStatus,@InvoicePrice,@CostPack,@SalesCost,@HoldbackAmount,@ListPrice,@MSRP,@LotLocation,@TagLine,@Certification,@CertificationNumber,@VehicleVIN,@VehicleYear,@VehicleMake,@VehicleModel,@VehicleModelCode,@VehicleTrim,@VehicleSubTrimLevel,@Classification,@TypeCode,@VehicleMileage,@EngineCylinderCount,@TransmissionType,@VehicleExteriorColor,@VehicleInteriorColor,@CreatedDate,@LastModifiedDate,@ModifiedFlag,@InteriorColorCode,@ExteriorColorCode,@PackageCode,@CodedCost,@Air,@OrderType,@AgeDays,@OutstandingRO,@DlrAccessoryRetail,@DlrAccessoryCost,@DlrAccessoryDesc,@ModelDesc,@Memo1,@Memo2,@Weight,@FloorPlan,@Purchaser,@PurchasedFrom,@InternetPrice,@InventoryAcctDollar,@VehicleType,@DealerAccessoryCode,@AllInventoryAcctDollar,@BestPrice,@InStock,@AccountingMake,@GasDiesel,@BookValue,@FactoryAccessoryDescription,@TotalReturn,@TotalCost,@SS,@VehicleBody,@StandardEquipment,@Account,@CalculatedPrice,@OriginalCost,@AccessoryCore,@OtherDollar,@PrimaryBookValue,@AmountDue,@LicenseFee,@ICompany,@InvenAcct,@Field23,@Field24,@SalesCode,@BaseRetail,@BaseInvAmt,@CommPrice,@Price1,@Price2,@StickerPrice,@TotInvAmt,@OptRetail,@OptInvAmt,@OptCost,@Options1,@Category,@Description,@Engine,@ModelType,@FTCode,@Wholesale,@Retail,@Draft,@ERRORNUMBER,@ERRORSEVERITY,@ERRORTABLE,@ERRORSTATE,@ERRORPROCEDURE,@ERRORLINE,@errormessage,@FtpDateEND CATCH-- PRINT @errornumber;-- PRINT @errorseverity;-- PRINT @errortable;-- PRINT @errorprocedure;-- PRINT @errorline;-- PRINT @errormessage;-- PRINT @errorstate;set @myerror = @@ERROR; -- This -- PRINT statement -- PRINTs 'Error = 0' because -- @@ERROR is reset in the IF statement above. -- PRINT N'Error = ' + @myerror;set @Inventoryid = scope_identity();-- PRINT @Inventoryid;--==========================================================================-- INSERT INTO DMS_INVENTORY_DETAILS (CHILD TABLE)--==========================================================================BEGIN TRYINSERT INTO [dbo].[DMS_INVENTORY_DETAILS] ( DMSInventoryID, StockType, DMSStatus, LotLocation, TagLine, Certification, CertificationNumber, CreatedDate, LastModifiedDate, ModifiedFlag, PackageCode, OrderType, AgeDays, OutstandingRO, Memo1, Memo2, Purchaser, PurchasedFrom, DealerAccessoryCode, InStock, AccountingMake, SS, Account, AccessoryCore, ICompany, InvenAcct, Field23, Field24, SalesCode, Draft, FTCode, FtpDate ) VALUES ( @InventoryID, @StockType, @DMSStatus, @LotLocation, @TagLine, @Certification, @CertificationNumber, @CreatedDate, @LastModifiedDate, @ModifiedFlag, @PackageCode, @OrderType, @AgeDays, @OutstandingRO, @Memo1, @Memo2, @Purchaser, @PurchasedFrom, @DealerAccessoryCode, @InStock, @AccountingMake, @SS, @Account, @AccessoryCore, @ICompany, @InvenAcct, @Field23, @Field24, @SalesCode, @Draft, @FTCode, @FtpDate );END TRY BEGIN CATCHSELECT @errornumber = ERROR_NUMBER(), @errorseverity = ERROR_SEVERITY(), @errorstate = ERROR_STATE(), @errortable = 'DMS_INVENTORY_DETAILS', @errorprocedure = ERROR_PROCEDURE(), @errorline = ERROR_LINE(), @errormessage = ERROR_MESSAGE();--==========================================================================-- INSERT ERRORS INTO DMSLOG_INVENTORY_ERROR--==========================================================================EXECUTE [SP_DMS_INVENTORY_ERROR] @FileType,@ACDealerID,@ClientDealerID,@DMSType,@StockNumber,@InventoryDate,@StockType,@DMSStatus,@InvoicePrice,@CostPack,@SalesCost,@HoldbackAmount,@ListPrice,@MSRP,@LotLocation,@TagLine,@Certification,@CertificationNumber,@VehicleVIN,@VehicleYear,@VehicleMake,@VehicleModel,@VehicleModelCode,@VehicleTrim,@VehicleSubTrimLevel,@Classification,@TypeCode,@VehicleMileage,@EngineCylinderCount,@TransmissionType,@VehicleExteriorColor,@VehicleInteriorColor,@CreatedDate,@LastModifiedDate,@ModifiedFlag,@InteriorColorCode,@ExteriorColorCode,@PackageCode,@CodedCost,@Air,@OrderType,@AgeDays,@OutstandingRO,@DlrAccessoryRetail,@DlrAccessoryCost,@DlrAccessoryDesc,@ModelDesc,@Memo1,@Memo2,@Weight,@FloorPlan,@Purchaser,@PurchasedFrom,@InternetPrice,@InventoryAcctDollar,@VehicleType,@DealerAccessoryCode,@AllInventoryAcctDollar,@BestPrice,@InStock,@AccountingMake,@GasDiesel,@BookValue,@FactoryAccessoryDescription,@TotalReturn,@TotalCost,@SS,@VehicleBody,@StandardEquipment,@Account,@CalculatedPrice,@OriginalCost,@AccessoryCore,@OtherDollar,@PrimaryBookValue,@AmountDue,@LicenseFee,@ICompany,@InvenAcct,@Field23,@Field24,@SalesCode,@BaseRetail,@BaseInvAmt,@CommPrice,@Price1,@Price2,@StickerPrice,@TotInvAmt,@OptRetail,@OptInvAmt,@OptCost,@Options1,@Category,@Description,@Engine,@ModelType,@FTCode,@Wholesale,@Retail,@Draft,@ERRORNUMBER,@ERRORSEVERITY,@ERRORTABLE,@ERRORSTATE,@ERRORPROCEDURE,@ERRORLINE,@errormessage,@FtpDateEND CATCH--==========================================================================-- INSERT INTO DMS_INVENTORY_AMOUNT (CHILD TABLE)--==========================================================================BEGIN TRYINSERT INTO [dbo].[DMS_INVENTORY_AMOUNT] ( DMSInventoryID, AllInventoryAcctDollar, OtherDollar, PrimaryBookValue, AmountDue, LicenseFee, CalculatedPrice, OriginalCost, BookValue, TotalReturn, TotalCost, DlrAccessoryRetail, DlrAccessoryCost, DlrAccessoryDesc, InternetPrice, InventoryAcctDollar, BestPrice, Weight, FloorPlan, CodedCost, InvoicePrice, CostPack, SalesCost, HoldbackAmount, ListPrice, MSRP, BaseRetail, BaseInvAmt, CommPrice, Price1, Price2, StickerPrice, TotInvAmt, OptRetail, OptInvAmt, OptCost, Wholesale, Retail, FtpDate ) VALUES ( @InventoryID, @AllInventoryAcctDollar, @OtherDollar, @PrimaryBookValue, @AmountDue, @LicenseFee, @CalculatedPrice, @OriginalCost, @BookValue, @TotalReturn, @TotalCost, @DlrAccessoryRetail, @DlrAccessoryCost, @DlrAccessoryDesc, @InternetPrice, @InventoryAcctDollar, @BestPrice, @Weight, @FloorPlan, @CodedCost, @InvoicePrice, @CostPack, @SalesCost, @HoldbackAmount, @ListPrice, @MSRP, @BaseRetail, @BaseInvAmt, @CommPrice, @Price1, @Price2, @StickerPrice, @TotInvAmt, @OptRetail, @OptInvAmt, @OptCost, @Wholesale, @Retail, @FtpDate ); END TRYBEGIN CATCHSELECT @errornumber = ERROR_NUMBER(), @errorseverity = ERROR_SEVERITY(), @errortable = 'DMS_INVENTORY_AMOUNT', @errorstate = ERROR_STATE(), @errorprocedure = ERROR_PROCEDURE(), @errorline = ERROR_LINE(), @errormessage = ERROR_MESSAGE();--==========================================================================-- INSERT ERRORS INTO DMSLOG_INVENTORY_ERROR--==========================================================================EXEC [SP_DMS_INVENTORY_ERROR] @FileType,@ACDealerID,@ClientDealerID,@DMSType,@StockNumber,@InventoryDate,@StockType,@DMSStatus,@InvoicePrice,@CostPack,@SalesCost,@HoldbackAmount,@ListPrice,@MSRP,@LotLocation,@TagLine,@Certification,@CertificationNumber,@VehicleVIN,@VehicleYear,@VehicleMake,@VehicleModel,@VehicleModelCode,@VehicleTrim,@VehicleSubTrimLevel,@Classification,@TypeCode,@VehicleMileage,@EngineCylinderCount,@TransmissionType,@VehicleExteriorColor,@VehicleInteriorColor,@CreatedDate,@LastModifiedDate,@ModifiedFlag,@InteriorColorCode,@ExteriorColorCode,@PackageCode,@CodedCost,@Air,@OrderType,@AgeDays,@OutstandingRO,@DlrAccessoryRetail,@DlrAccessoryCost,@DlrAccessoryDesc,@ModelDesc,@Memo1,@Memo2,@Weight,@FloorPlan,@Purchaser,@PurchasedFrom,@InternetPrice,@InventoryAcctDollar,@VehicleType,@DealerAccessoryCode,@AllInventoryAcctDollar,@BestPrice,@InStock,@AccountingMake,@GasDiesel,@BookValue,@FactoryAccessoryDescription,@TotalReturn,@TotalCost,@SS,@VehicleBody,@StandardEquipment,@Account,@CalculatedPrice,@OriginalCost,@AccessoryCore,@OtherDollar,@PrimaryBookValue,@AmountDue,@LicenseFee,@ICompany,@InvenAcct,@Field23,@Field24,@SalesCode,@BaseRetail,@BaseInvAmt,@CommPrice,@Price1,@Price2,@StickerPrice,@TotInvAmt,@OptRetail,@OptInvAmt,@OptCost,@Options1,@Category,@Description,@Engine,@ModelType,@FTCode,@Wholesale,@Retail,@Draft,@ERRORNUMBER,@ERRORSEVERITY,@ERRORTABLE,@ERRORSTATE,@ERRORPROCEDURE,@ERRORLINE,@errormessage,@FtpDateEND CATCH--==========================================================================-- INSERT INTO DMS_INVENTORY_VEHICLE (CHILD TABLE)--==========================================================================BEGIN TRYINSERT INTO [dbo].[DMS_INVENTORY_VEHICLE] ( DMSInventoryID, InteriorColorCode, ExteriorColorCode, Air, ModelDesc, VehicleType, VehicleVIN, VehicleYear, VehicleMake, VehicleModel, VehicleModelCode, VehicleTrim, VehicleSubTrimLevel, Classification, TypeCode, VehicleMileage, FtpDate, EngineCylinderCount ) VALUES ( @InventoryID, @InteriorColorCode, @ExteriorColorCode, @Air, @ModelDesc, @VehicleType, @VehicleVIN, @VehicleYear, @VehicleMake, @VehicleModel, @VehicleModelCode, @VehicleTrim, @VehicleSubTrimLevel, @Classification, @TypeCode, @VehicleMileage, @FtpDate, @EngineCylinderCount );END TRY BEGIN CATCHSELECT @errornumber = ERROR_NUMBER(), @errorseverity = ERROR_SEVERITY(), @errortable = 'DMS_INVENTORY_VEHICLE', @errorstate = ERROR_STATE(), @errorprocedure = ERROR_PROCEDURE(), @errorline = ERROR_LINE(), @errormessage = ERROR_MESSAGE();--==========================================================================-- INSERT ERRORS INTO DMSLOG_INVENTORY_ERROR --==========================================================================EXEC [SP_DMS_INVENTORY_ERROR] @FileType,@ACDealerID,@ClientDealerID,@DMSType,@StockNumber,@InventoryDate,@StockType,@DMSStatus,@InvoicePrice,@CostPack,@SalesCost,@HoldbackAmount,@ListPrice,@MSRP,@LotLocation,@TagLine,@Certification,@CertificationNumber,@VehicleVIN,@VehicleYear,@VehicleMake,@VehicleModel,@VehicleModelCode,@VehicleTrim,@VehicleSubTrimLevel,@Classification,@TypeCode,@VehicleMileage,@EngineCylinderCount,@TransmissionType,@VehicleExteriorColor,@VehicleInteriorColor,@CreatedDate,@LastModifiedDate,@ModifiedFlag,@InteriorColorCode,@ExteriorColorCode,@PackageCode,@CodedCost,@Air,@OrderType,@AgeDays,@OutstandingRO,@DlrAccessoryRetail,@DlrAccessoryCost,@DlrAccessoryDesc,@ModelDesc,@Memo1,@Memo2,@Weight,@FloorPlan,@Purchaser,@PurchasedFrom,@InternetPrice,@InventoryAcctDollar,@VehicleType,@DealerAccessoryCode,@AllInventoryAcctDollar,@BestPrice,@InStock,@AccountingMake,@GasDiesel,@BookValue,@FactoryAccessoryDescription,@TotalReturn,@TotalCost,@SS,@VehicleBody,@StandardEquipment,@Account,@CalculatedPrice,@OriginalCost,@AccessoryCore,@OtherDollar,@PrimaryBookValue,@AmountDue,@LicenseFee,@ICompany,@InvenAcct,@Field23,@Field24,@SalesCode,@BaseRetail,@BaseInvAmt,@CommPrice,@Price1,@Price2,@StickerPrice,@TotInvAmt,@OptRetail,@OptInvAmt,@OptCost,@Options1,@Category,@Description,@Engine,@ModelType,@FTCode,@Wholesale,@Retail,@Draft,@ERRORNUMBER,@ERRORSEVERITY,@ERRORTABLE,@ERRORSTATE,@ERRORPROCEDURE,@ERRORLINE,@errormessage,@FtpDateEND CATCH--==========================================================================-- MOVE CURSUR TO NEXT RECORD--========================================================================== FETCH NEXT FROM Inventory_Cursor INTO @FileType , @ACDealerID , @ClientDealerID , @DMSType , @StockNumber , @InventoryDate , @StockType , @DMSStatus , @InvoicePrice , @CostPack , @SalesCost , @HoldbackAmount , @ListPrice , @MSRP , @LotLocation , @TagLine , @Certification , @CertificationNumber , @VehicleVIN , @VehicleYear , @VehicleMake , @VehicleModel , @VehicleModelCode , @VehicleTrim , @VehicleSubTrimLevel , @Classification , @TypeCode , @VehicleMileage , @EngineCylinderCount , @TransmissionType , @VehicleExteriorColor , @VehicleInteriorColor , @CreatedDate , @LastModifiedDate , @ModifiedFlag , @InteriorColorCode , @ExteriorColorCode , @PackageCode , @CodedCost , @Air , @OrderType , @AgeDays , @OutstandingRO , @DlrAccessoryRetail , @DlrAccessoryCost , @DlrAccessoryDesc , @ModelDesc , @Memo1 , @Memo2 , @Weight , @FloorPlan , @Purchaser , @PurchasedFrom , @InternetPrice , @InventoryAcctDollar , @VehicleType , @DealerAccessoryCode , @AllInventoryAcctDollar , @BestPrice , @InStock , @AccountingMake , @GasDiesel , @BookValue , @FactoryAccessoryDescription , @TotalReturn , @TotalCost , @SS , @VehicleBody , @StandardEquipment , @Account , @CalculatedPrice , @OriginalCost , @AccessoryCore , @OtherDollar , @PrimaryBookValue , @AmountDue , @LicenseFee , @ICompany , @InvenAcct , @Field23 , @Field24 , @SalesCode , @BaseRetail , @BaseInvAmt , @CommPrice , @Price1 , @Price2 , @StickerPrice , @TotInvAmt , @OptRetail , @OptInvAmt , @OptCost , @Options1 , @Category , @Description , @Engine , @ModelType , @FTCode , @Wholesale , @Retail , @Draft , @flatfile_createddate, @FtpDate;END CLOSE Inventory_Cursor;DEALLOCATE Inventory_Cursor;SET ANSI_PADDING OFFEND |
|
namman
Constraint Violating Yak Guru
285 Posts |
Posted - 2015-03-06 : 13:15:36
|
Quick look at the stored procedure, I see that your requirement is like : check row by row, if valid, insert into tables, if invalid do something else (via another sp). If so, the cursor is the right one. Set based solution is not for this requirement. |
|
|
|
|
|