Skip to content Skip to sidebar Skip to footer

If-else Statement In Db2/400

I am trying to run an SQL that contains if-else statement in AS400 but it doesn't work. I am creating a View using i Series Navigator in order to run it. SELECT IF FIELD1 IS NOT N

Solution 1:

Use CASE expression instead:

SELECTCASEWHEN FIELD1 ISNOTNULLTHEN'AAA'ELSE'BBB'ENDFROM LIB.TABLE1;

IF is control-flow construct:

IF conditionTHENSELECT ...
ELSESELECT ...
END IF

Solution 2:

SELECT ABC, DEF,
CASEWHEN (substring(GHI,1,4)) IS'SOTH'THEN'J'ELSE'N'ENDas SOTH
WHERE ABC like'ABC%'GROUPBY ABC,DEF,GHI

Post a Comment for "If-else Statement In Db2/400"