Easily Create COALESCE in SSIS Expressions
Caveat: REPLACENULL was introduced in SSIS 2012. For earlier versions, ISNULL is the best option.
There's no COALESCE function within SSIS expressions, nor a way to achieve it without using nested statements. The built-in ISNULL function works well for one or two null evaluations or to perform additional logic based on null values, but becomes syntactically difficult to write and read for COALESCE type operations. REPLACENULL does the trick a little more cleanly. Below is an example:
Add
Essentially, you're telling SSIS to replace the null in the first column with the second column, which is also checks to replace the second column's null with the third column. When all of these have been checked and all evaluate to null, the default value is set.
There's no COALESCE function within SSIS expressions, nor a way to achieve it without using nested statements. The built-in ISNULL function works well for one or two null evaluations or to perform additional logic based on null values, but becomes syntactically difficult to write and read for COALESCE type operations. REPLACENULL does the trick a little more cleanly. Below is an example:
REPLACENULL([Column1],REPLACENULL([Column2],REPLACENULL([Column3],"Unknown")))
Add
REPLACENULL([ColumnN],
for each column. The final mention of your columns should be followed by your default value when all of the columns are null (e.g. NULL
, "Unknown"
, 0). Close the whole statement by adding the same number of parentheses after the default value as the number of columns evaluated in the statement (in this case, three).Essentially, you're telling SSIS to replace the null in the first column with the second column, which is also checks to replace the second column's null with the third column. When all of these have been checked and all evaluate to null, the default value is set.
Comments
Post a Comment