【问题标题】:SSIS has validation error on SQL Server stored procedureSSIS 在 SQL Server 存储过程中出现验证错误
【发布时间】:2015-01-08 19:19:22
【问题描述】:

我正在尝试从 Visual Studio 2012 中的 SSIS 调用 SQL Server 2008 R2 中的自定义存储过程。我在 SSMS 2012 中编写并测试了该存储过程,它按预期工作。

但是,当我尝试将其放置在 OLE DB 命令组件中时,当我刷新组件或 SSIS 包验证时收到除以 0 错误。

这是存储过程的代码:

CREATE PROCEDURE [ldg].[2015HRUpdate(TEST)]
    @Employee varchar(20),                      -- maps to EM.Employee, primary key
    @Title varchar(50),                         -- maps to EM.Title
    @PayRate varchar(50) = '0',              -- maps to EM.JobCostRate, convert to decimal
    --  @Percentage Decimal(19,4) = 0,            -- workaround
    @OldPayRate Decimal(19,4) = 0,           -- used to calculate Employees_SalaryHistory.Custnprcent, convert to decimal
    @LaborCategory varchar(50) = '0',           -- maps to EM.BillingCategory, convert to small int
    @EmployeeDesignation varchar(50),           -- maps to EmployeeCustomTabFields.CustEmployeeDesg
    @FSLAStatus varchar(50),                    -- maps to EmployeeCustomTabFields.CustFSLAStatus
    @Supervisor varchar(20),                    -- maps to EM.Supervisor
    @SupervisorName varchar(255),               -- maps to Employees_SalaryHistory.custSuper
    @ModUser nvarchar(20),
    @ModDate datetime
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Convert data types to match database data types
    declare @JobCostRate decimal(19,4);
    declare @OldJobCostRate decimal(19,4);
    declare @BillingCategory smallint;
    declare @Percent decimal(19,4);

    if @PayRate is null or @PayRate = '' 
      set @PayRate = '0';


    set @JobCostRate = CONVERT(decimal(19,4), @PayRate); 
    set @OldJobCostRate = @OldPayRate;

    /* this works in T-SQL but when SSIS tries to validate I get a div/0 error */
    if @OldJobCostRate != 0
    begin 
      set @Percent = ((@JobCostRate - @OldJobCostRate)/@OldJobCostRate) * 100;  --errors out right here with a divide by 0 error.
      --set @Percent = 0;
    end 
    else
    begin
      set @Percent = 0;
    end

    set @BillingCategory = CONVERT(smallint, @LaborCategory);

    -- SQL statements for procedure here    
      -- Update EM table
    -- Update EmployeeCustomTabFields table
    -- Insert into Salary history table
END
GO

我已在产生错误的行上添加了注释。如果我注释掉该行并取消注释它下面的行,SSIS 将验证该过程而不会出现问题。

我终于通过在 ETL 中创建派生字段解决了这个问题,但我想知道为什么 SSIS/OLE-DB 在下次弹出时会导致此问题。

谢谢, 罗伊

【问题讨论】:

    标签: sql-server ssis sql-server-2008-r2 oledb


    【解决方案1】:

    如果你改变你的程序看起来像

    SET NOCOUNT ON;
    -- This is a bloody hack to get SSIS to be happy about metadata. 
    IF 1=2
    BEGIN
        SELECT 1 AS StupidHackery;
    END 
    

    我相信你会解决这个问题。根本原因是 SSIS 想要验证来自 proc 的元数据并且实际上并没有评估那里的逻辑。遗憾的是,我没有关于此事的任何明确资源,但至少对我来说,我可以重现你的问题,并通过使用这个愚蠢的黑客来解决它。在处理临时表时,我不得不使用相同的东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-04
      • 1970-01-01
      • 1970-01-01
      • 2015-06-14
      • 2023-04-08
      相关资源
      最近更新 更多