Tirtha Roy Chowdhury
Tirtha Roy Chowdhury

Reputation: 77

The data types "DT_WSTR" and "DT_I4" are incompatible for binary operator "=="

I am using the following expression:

[TIMEPERIOD_ID]==1?"JANUARY":
[TIMEPERIOD_ID]==2?"FEBRUARY":
[TIMEPERIOD_ID]==3?"MARCH": 
[TIMEPERIOD_ID]==4?"APRIL":
[TIMEPERIOD_ID]==5?"MAY":
[TIMEPERIOD_ID]==6?"JUNE":
[TIMEPERIOD_ID]==7?"JULY":
[TIMEPERIOD_ID]==8?"AUGUST":
[TIMEPERIOD_ID]==9?"SEPTEMBER":
[TIMEPERIOD_ID]==10?"OCTOBER":
[TIMEPERIOD_ID]==11?"NOVEMBER":
[TIMEPERIOD_ID]==12?"DECEMBER"

And it throws the following exception:

ERROR - The data types "DT_WSTR" and "DT_I4" are incompatible for binary operator "==". The operand types could not be implicitly cast into compatible types for the operation. To perform this operation, one or both operands need to be explicitly cast with a cast operator.

Any suggestions?

Upvotes: 1

Views: 8220

Answers (1)

Hadi
Hadi

Reputation: 37313

From the error mentioned, it looks like [TIMEPERIOD_ID] data type is DT_WSTR and it cannot be compared to integer values. Try the following expression:

[TIMEPERIOD_ID] == "1" ? "JANUARY" :
[TIMEPERIOD_ID] == "2" ? "FEBRUARY" :
[TIMEPERIOD_ID] == "3" ? "MARCH" : 
[TIMEPERIOD_ID] == "4" ? "APRIL" :
[TIMEPERIOD_ID] == "5" ? "MAY" :
[TIMEPERIOD_ID] == "6" ? "JUNE" :
[TIMEPERIOD_ID] == "7" ? "JULY" : 
[TIMEPERIOD_ID] == "8" ? "AUGUST" :
[TIMEPERIOD_ID] == "9" ? "SEPTEMBER" :
[TIMEPERIOD_ID] == "10" ? "OCTOBER" :
[TIMEPERIOD_ID] == "11" ? "NOVEMBER" :
[TIMEPERIOD_ID] == "12" ? "DECEMBER" : ""

Upvotes: 3

Related Questions