【发布时间】: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