Q:

How to use TRIM in nested if conditional expression in SSIS derived column

I have a source table with two columns - Sndr_Ref and Check_Num
I have a target table with one column - Txn_Code (nvarchar(50),null)
Here is the logic I need to implement -

If Sndr_Ref = [some value] and Check_Num = null, then load Txn_Code = 10
If Check_Num = [some value] and Sndr_Ref = null, then load Txn_Code = 2
If both Sndr_Ref and Check_Num = [some value], then load Txn_Code = 10
If both Sndr_Ref and Check_Num = Null, then load Txn_Code = Null

I created a derived column in my SSIS package which I mapped to Txn_Code. Here is the expression of my derived column -
Sndr_Ref == "" ? (Check_Num == "" ? (DT_WSTR,50)NULL(DT_WSTR,50) : "2") : "10"

The above expression is inserting 10 in all records. No nulls or 2 are being inserted. I checked the source table and there should be some records with 10, 2 and nulls in target column. I just found out that my source reference columns (Sndr_Ref and Check_Num) have widespaces. Could you please help how can I trim those widespaces in my above logic and set the value to null if they are blank?

A:

not sure about your source data but I guess you may need to check for nulls as well:
ISNULL(Sndr_Ref) || TRIM(Sndr_Ref) == "" ? (ISNULL(Check_Num) || TRIM(Check_Num) == "" ? (DT_WSTR,50)NULL(DT_WSTR,50) : "2") : "10"

