Db2

 View Only
Expand all | Collapse all

Define Nested If statements in Workbench Db2 Web Query

  • 1.  Define Nested If statements in Workbench Db2 Web Query

    Posted Wed December 16, 2020 07:07 PM

    I am trying to define & group GL accounts with If statements in DB2 Workbench. Every time I do it, i keep getting a syntax error. I tried with just one statement so far to see if I can get it right before I add the rest.

    IF (AND ( APHGL# GE '6100',APHGL# LE '6199') THEN 'CONTAINER EXPENSES' ELSE "")

    My errors:

    FOC262) UNBALANCED PARENTHESES

    IF (AND ( APHGL# GE '6100',APHGL# LE '6199') THEN 'CONTAINER EXPENSES' ELSE "")

    (FOC266) IF .. THEN .. ELSE .. SYNTAX ERROR

    IF (AND ( APHGL# GE '6100',APHGL# LE '6199') THEN 'CONTAINER EXPENSES' ELSE "")

    (FOC224) SYNTAX ERROR: ELSE

    IF (AND ( APHGL# GE '6100',APHGL# LE '6199') THEN 'CONTAINER EXPENSES' ELSE "")

    The categories are below I am trying to define. Please help If you can

    COST OF GOODS SOLD: 5300

    CONTAINER EXPENSES: 6100 TO 6199

    CUSTOMS FINES: 6200

    P/L: 6300

    LINE EXPENSES:6400 TO 6499

    VESSEL EXPENSES: 6500 TO 6599






    #Db2
    #Support
    #SupportMigration


  • 2.  RE: Define Nested If statements in Workbench Db2 Web Query

    Posted Thu December 17, 2020 04:58 PM

    The IF statement should be written as:

    IF APHGL# EQ '5300' THEN 'COST OF GOODS SOLD' ELSE IF APHGL# GE '6100' AND APHGL# LE '6199' THEN 'CONTAINER EXPENSES' ELSE IF APHGL# EQ '6200' THEN 'CUSTOMS FINES' ELSE IF APHGL# EQ '6300' THEN 'P/L' ELSE IF APHGL# GE '6400' AND APHGL# LE '6499' THEN 'LINE EXPENSES' ELSE IF APHGL# GE '6500' AND APHGL# LE '6599' THEN 'VESSEL EXPENSES' ELSE 'UNKNOWN GL ACCOUNT'

    Assuming the APHGL# is actually a four character alpha field. If it is a numeric field, drop the single quotes (i.e. APHGL# GE 6400 AND APHGL# LE 6499)






    #Db2
    #Support
    #SupportMigration


  • 3.  RE: Define Nested If statements in Workbench Db2 Web Query

    Posted Fri December 18, 2020 05:34 PM

    Thank you so much! It is valid now and works.






    #Db2
    #Support
    #SupportMigration