Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSIS Derived Column (if then...else)

Tags:

ssis

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

like image 707
Unal Avatar asked Jan 23 '13 19:01

Unal


People also ask

How do you derive columns in SSIS?

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.

How do I use Findstring in SSIS?

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.

How conditional split transformation is used in SSIS with example?

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.


1 Answers

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.

like image 188
billinkc Avatar answered Jan 04 '23 06:01

billinkc