Wednesday, March 7, 2012

expression

Hi,

In ssis I would like to map a column from table a to a column in table b

Currently this is how I am doing it using sql.

I believe I have to use a derived column but not sure how to implement if statement inside it.

Thanks

case

when len([Column 5]) = 0 then ''

when lower([Column 5]) = 'unknown' then ''

when isdate([Column 5]) = 1 then substring(ltrim([Column 5]), 1, 4) + substring(ltrim([Column 5]), 6, 2) + substring(ltrim([Column 5]), 9, 2)

else

null

end,

Why not just leave it as is and use the SQL you've already got written?

The big problem is that there is no "isdate" function in the SSIS derived column transformation. So you'll end up writing a script to do that, which isn't hard, but if you're going to write the code anyway, you might as well just keep what you've got already in place.|||

Yes you are right but I am trying to learn how to use if inside the expression when mapping fields.

For example I can map two fields to each other but not sure how to include the if statement for that particular mapping. Thanks

|||

arkiboys wrote:

Yes you are right but I am trying to learn how to use if inside the expression when mapping fields.

For example I can map two fields to each other but not sure how to include the if statement for that particular mapping. Thanks

If ... else in an expression looks like this:

(condition to evaluate) ? true : false

So you might have:

(1 + 1) == 2 ? "YES" : "NO" - which will return "YES" obviously

In your example, without the "isdate" test:

LEN([Column 5]) == 0 ? '' : LOWER([Column 5]) == 'unknown' ? '' : etc....

No comments:

Post a Comment