is there a way of replicating the below expression in SSIS Derived Column?
SELECT CASE
WHEN LEN(column1) > 8
THEN
column1
ELSE
REPLICATE('0', 18 - LEN(column1)) + column1
END AS column1
FROM myTable
I want to pad the value of column1 with 0 if the lenght of the value is less than 8 character
To start using the Derived Column transformation, create an SSIS package. Next, drag a Data Flow component in the Control Flow, double-click the Data Flow component and drag a data source component. Then, configure the data source to connect to your database. Finally, add a Derived Column transformation component.
FINDSTRING works only with the DT_WSTR data type. character_expression and searchstring arguments that are string literals or data columns with the DT_STR data type are implicitly cast to the DT_WSTR data type before FINDSTRING performs its operation. Other data types must be explicitly cast to the DT_WSTR data type.
The Conditional Split transformation checks the given condition and route data to appropriate destination depending on the given condition. For example if a men's age is greater than 66 then He can go it into the Senior citizen quota or else He will not be considered as senior citizen.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With