How to use coalesce in ssis

6k views Asked by At

I am using MS SSIS 2008 and I want to perform COALESCE function in DERIVED COLUMN function.

Could you help me how to write the expression?

3

There are 3 answers

1
billinkc On

We don't have a coalesce function. The ISNULL in our Expression language differs greatly from the TSQL function of the same name.

The SSIS Expression language's ISNULL evaluates an operand and returns true if it is the null value, otherwise it returns false.

Instead, to perform a coalesce-like operation, we need to make use of the ISNULL operator and the ternary function ?: Read it as Test : True condition : False condition. Assuming MyColumn was of type unicode string, this would determine whether MyColumn was false. If it is, it would hard code the string Secondary Condition. Otherwise, it would return the value of MyColumn. This would be equivalent to tsql's `coalesce(MyColumn, 'Secondary Condition')

ISNULL(MyColumn) ? "Secondary Condition" : MyColumn

Coalesce allows for multiple search conditions so something like coalesce(Column0, Column1, Column2) would nest the ternary operators together

ISNULL(Column0) ? (ISNULL(Column1) ? Column2: Column1) : Column0

This gets ugly rather quickly but the concept remains the same - continue nesting until you've matched all the levels you need to check.

1
Ravi Teja On

Coalesce function is only limited to TSQL. either in SSIS/SSRS we don't have Coalesce function. So to get the desired output we have to use ISNULL or ISNOTHING functions in SSIS/SSRS. In this case it would be the nested ISNULL function.

1
Linda C On

You can use REPLACENULL( «expression», «expression» ) from Derived Column Transformation Editor. Just put your column in the first expression and the default value in the second expression.

For example, REPLACENULL([some_internal_id], 0)