Sarah Sarah - 4 months ago 12
SQL Question

Conditional ? : SSIS

(ISNULL([Deal Status]) ? "2" : SUBSTRING([Deal Status],1,1)) == "2"

This is one of the outputs in a conditional split in SSIS.

I Don't understand what this means. Could you help explain this?

I understand: If Deal Status is null, return 2, else check if dealstatus is 2?


When using the ? and :, it's a conditional operator, the same as using an if/else statement:

condition ? true result : false result

So to breakdown what your statement is doing, it first checks to see if DealStatus IS NULL. If so, it returns a "2". If it isn't NULL, it returns the first character of the DealStatus field using SUBSTRING. Finally, it compares that result to see if it's equal to "2".

The overall expression will return a true/false. For example, if DealStatus is NULL, this will always return true.

For example, here would be the results if the following values were stored in the DealStatus field.

DealStatus    ResultOfCondition
NULL          true (because DealStatus is NULL, we compare 2 == 2 is true)
123           false (because the first character is 1, 1 == 2 is false)
234           true (because the first character is 2, 2 == 2 is true)