How to only do a decode if the field is not null

Highlighted
Five Stars

How to only do a decode if the field is not null

Hi I am currently using the code below for a decode but getting a null pointer when the value is null. Can someone let me know how I could check to see if the column is null before I do the decode. Below is my code

 

If not null then do below

(row1.PFR_REGION.equals("GULF"))?"3": (row1.PFR_REGION.equals("SF"))?"2": (row1.PFR_REGION.equals("QUEBEC"))?"6":row1.STATUS


Accepted Solutions
Highlighted
Sixteen Stars
Sixteen Stars

Re: How to only do a decode if the field is not null

You can just reverse the comparisons if you want row1.Status as the default value:

"GULF".equals(row1.PFR_REGION) ? "3" :
  "SF".equals(row1.PFR_REGION) ? "2" :
      "QUEBEC".equals(row1.PFR_REGION) ? "6" : row1.STATUS

Else, if you want an other default value, change the expression like this:

row1.PFR_REGION == null ? "YOUR DEFAULT VALUE" :
    "GULF".equals(row1.PFR_REGION) ? "3" :
        "SF".equals(row1.PFR_REGION) ? "2" :
            "QUEBEC".equals(row1.PFR_REGION) ? "6" : row1.STATUS

TRF

View solution in original post


All Replies
Highlighted
Sixteen Stars
Sixteen Stars

Re: How to only do a decode if the field is not null

You can just reverse the comparisons if you want row1.Status as the default value:

"GULF".equals(row1.PFR_REGION) ? "3" :
  "SF".equals(row1.PFR_REGION) ? "2" :
      "QUEBEC".equals(row1.PFR_REGION) ? "6" : row1.STATUS

Else, if you want an other default value, change the expression like this:

row1.PFR_REGION == null ? "YOUR DEFAULT VALUE" :
    "GULF".equals(row1.PFR_REGION) ? "3" :
        "SF".equals(row1.PFR_REGION) ? "2" :
            "QUEBEC".equals(row1.PFR_REGION) ? "6" : row1.STATUS

TRF

View solution in original post

Highlighted
Five Stars

Re: How to only do a decode if the field is not null

Thanks very much it works!

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog