Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
799 views
in Technique[技术] by (71.8m points)

ssis - Failure in adding new transformed column

First question here :)

I'm working on a project where i need to copy only 3 columns from Employee table (ID, Firstname, Lastname) from DB to an Excel worksheet destination,

and i need to create new column that will be called "Seniority".

I was thinking to take the "HireDate" (I've thought to map it also for the derived column transformation) of all employees and transform it to years of seniority.

In the Derived Column Transformation Editor i put these values:

Derived column name - Seniority

Derived column -

Expression - (DT_I4) DATEDIFF( "YEAR", YEAR( [HireDate] ) , YEAR( GETDATE() ) )

and got this error:

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)

Please help.

Thanks,


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The function YEAR([HireDate]) returns an DT_I4(four-byte signed integer) but the DATEDIFF function needs two dates as parameters. So the expression

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

returns the desired result.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...