Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Talend experts
I am having difficulty comparing string. When I use following expression it doesnt seem to be working.
Relational.ISNULL(Stg_Unit_enrol.Unit_enrolment_code) || Stg_Unit_enrol.Deleted_Flag.equals("Y") ? context.NotAvailableCode : Stg_Unit_enrol.Unit_enrolment_code
Ideally when my deleted_flag='Y' then it should show -2 value but somehow it is not showing.
Just for info. deleted_flag contains null values too.
Is there anything I am doing wrong here?
Thanks
Harshal.
@Parikhharshal,i am assuming that your comparing sting field and the output field also sting right? that should work and check below one also working.
Stg_Unit_enrol.Unit_enrolment_code==null || Stg_Unit_enrol.Deleted_Flag.equals("Y") ? context.NotAvailableCode : Stg_Unit_enrol.Unit_enrolment_code
You did not mention what data type is Stg_Unit_enrol.Deleted_Flag. If it is String code the equals as: Stg_Unit_enrol.Deleted_Flag.equals("Y") and if it is char code the equals as: Stg_Unit_enrol.Deleted_Flag.equals('Y'). Notice the use of single quote for char type and a double quote for String type.
@Parikhharshal,then try with below one?
Stg_Unit_enrol.Unit_enrolment_code==null || Stg_Unit_enrol.Deleted_Flag.equals("Y") ? context.NotAvailableCode : Stg_Unit_enrol.Unit_enrolment_code
@Parikhharshal,still do you have issue the expression?
An improvement to your expression, you should fail at null check because comparing a null with a string will cause an exception. The expression would be:
!Stg_Unit_enrol.Unit_enrolment_code==null && Stg_Unit_enrol.Deleted_Flag.equals("Y") ? context.NotAvailableCode : Stg_Unit_enrol.Unit_enrolment_code
alternative syntax...
Stg_Unit_enrol.Unit_enrolment_code!=null && Stg_Unit_enrol.Deleted_Flag.equals("Y") ? context.NotAvailableCode : Stg_Unit_enrol.Unit_enrolment_code
Which reads "if the Stg_Unit_enrol.Unit_enrolment_code is not null, then go on to the next testing for its Y value". So, you don't fall into the trap of testing a string against a null value.
Or just:
"Y".equals(Stg_Unit_enrol.Deleted_Flag.equals) ? context.NotAvailableCode : Stg_Unit_enrol.Unit_enrolment_code
As soon as "Y" cannot be null, you are still protected against NPE.