SSIS Derived Column (if then...else)

The SSIS expression language supports the ternary operator ? :

(LEN([column1]) > 8) ? column1 : replicate("0", (18 - LEN([column1]))) + [column1]

That expression ought to work but it doesn't because the REPLICATE call is going to provide metadata back stating it's 4k nvarchar characters (the limit). If you're deadset on getting it to work that way, comment and I'll hack the expression to size the output of replicate before concatenating with column1

An easier approach is to just always add 8 leading zeros to the expression and then slice it off from the right.

RIGHT(REPLICATE("0",8) + column1,8)

You might need 18 on the second as your example seemed to use 18 but the concept will be the same.

Tags:

Ssis