ISNULL function in SSIS

Ajinkya Pujari picture Ajinkya Pujari · Jun 1, 2018 · Viewed 7k times · Source

I have a column PhoneNumber varchar(50) and i want to build an expression for a derived column PhoneNumberType varchar(50) based on below,

IF PhoneNumber <> NULL then
Set to ""Office""
Else
Set to NULL
END IF

I tried as

!ISNULL(PhoneNumber ) ? "Office" : PhoneNumber 

But i am getting an error while mapping the column as

Column PhoneNumberType can not convert between unicode and non-unicode string data types

Update : Can i just go to the advance editor of derived column component and select string [DT_STR] instead of auto generated , unicode string [DT_WSTR] data type in column properties ?

is this a good practice ?

Answer

Hadi picture Hadi · Jun 3, 2018

You can use the following expression to generate a DT_STR column and it also check for empty strings:

ISNULL([PhoneNumber]) || TRIM(PhoneNumber) == "" ? NULL(DT_STR, 50, 1252) : (DT_STR,50,1252)"Office"