Question

(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?

Was it helpful?

Solution

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)

OTHER TIPS

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

DealStatus=null

(ISNULL([Deal Status]) ? "2" : SUBSTRING([Deal Status],1,1)) == "2" it will verifies the first condition, DealStatus value is null so it will display(true condition) the after ? value whatever is there , In this scenario "2" is there after "?" it will display the 2.so 2=2

DealStatus=256

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

it will checks the first condition, but DealStatus value is not null so it will check the second condition it will produce the out put is 2 .so 2=2.

Substring Ex:-

Select SUBSTRING('258',1,1) o/p:- 2

Select SUBSTRING('589',1,1) o/p:- 5

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top