Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Parikhharshal
Creator III
Creator III

string compare in tmap

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.

Labels (3)
8 Replies
manodwhb
Champion II
Champion II

@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

skorp
Contributor
Contributor

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
Creator III
Creator III
Author

It is string.
manodwhb
Champion II
Champion II

@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

manodwhb
Champion II
Champion II

@Parikhharshal,still do you have issue the expression?

skorp
Contributor
Contributor

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.

TRF
Champion II
Champion II

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.

Parikhharshal
Creator III
Creator III
Author

Thanks a lot for your reply TRF.