添加新转换列失败

Failure in adding new transformed column

这里是第一个问题:)

我正在做一个项目,我只需要将员工 table(ID、名字、姓氏)中的 3 列从数据库复制到 Excel 工作表目标,

我需要创建一个名为“Seniority”的新列。

我正在考虑将所有员工的“HireDate”(我也想过将其映射到派生列转换)并将其转换为工龄。

在派生列转换编辑器中,我输入了这些值:

派生列名称 - 资历

派生列 -

表达式 - (DT_I4) DATEDIFF( "YEAR", YEAR( [HireDate] ) , YEAR( GETDATE() ) )

并收到此错误:

Error at Data Flow Task [Derived Column [234]]: The function "DATEDIFF" does not support the data type "DT_I4" for parameter number 2. The type of the parameter could not be implicitly cast into a compatible type for the function. To perform this operation, the operand needs to be explicitly cast with a cast operator.

Error at Data Flow Task [Derived Column [234]]: Evaluating function "DATEDIFF" failed with error code 0xC0047089.

Error at Data Flow Task [Derived Column [234]]: The function "DATEDIFF" does not support the data type "DT_I4" for parameter number 2. The type of the parameter could not be implicitly cast into a compatible type for the function. To perform this operation, the operand needs to be explicitly cast with a cast operator.

Error at Data Flow Task [Derived Column [234]]: Computing the expression "(DT_I4) DATEDIFF( "YEAR", YEAR( [HireDate] ) , YEAR( GETDATE() ) )" failed with error code 0xC00470C5. The expression may have errors, such as divide by zero, that cannot be detected at parse time, or there may be an out-of-memory error.

Error at Data Flow Task [Derived Column [234]]: The expression "(DT_I4) DATEDIFF( "YEAR", YEAR( [HireDate] ) , YEAR( GETDATE() ) )" on "Derived Column.Outputs[Derived Column Output].Columns[Seniority]" is not valid.

Error at Data Flow Task [Derived Column [234]]: Failed to set property "Expression" on "Derived Column.Outputs[Derived Column Output].Columns[Seniority]".

(Microsoft Visual Studio)

请帮忙

谢谢,

函数 YEAR([HireDate]) returns 一个 DT_I4(四字节带符号整数)但是 DATEDIFF 函数需要两个日期作为参数。 所以表达式

DATEDIFF("YEAR",[HireDate],GETDATE())

returns 想要的结果。