Search code examples
openedgeprogress-db

IF THEN causing syntax [OPENEDGE]Syntax error (10713)


I'm trying to write an IF/THEN/ELSE against Progress OpenEdge and getting syntax errors on every iteration I've tried. I'm trying to select a group of columns and doing a couple of calculations. One calc is dividing two columns so I'm trying to check the divisor column in case it is zero.

I'm getting the following error with slight variations of what it doesn't like in the statement depending on what variation of the IF/THEN I use.

ERROR [HY000] [DataDirect][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE] 
Syntax error in SQL statement at or about "= 0 THEN ColumnA ELSE (ColumnA " (10713)

This is my current iteration (with columns renamed to protect the innocent. ;)

, IF ColumnA = 0 THEN ColumnA 
    ELSE (ColumnA - ColumnB) / ColumnB
    END as ProfitMargin

I started with aliased columns (POS.ColumnA & POS.ColumnB) and read somewhere that fully qualified columns could cause issues so I dropped the alias.

I tried IF POS.ColumnA = 0 THEN 0. I also tried putting in ELSE DO: I have put an END after the THEN ColumnA. I have put the full calculation in another set of parens.

I throw myself on the mercy of S.O. What am I missing?


Solution

  • I do not see IF/THEN/ELSE anywhere in the OpenEdge SQL docs:

    https://documentation.progress.com/output/OpenEdge117/openedge117/#page/dmsrf/preface.html#

    or:

    https://documentation.progress.com/output/OpenEdge117/openedge117/#page/dmsrf%2Fsearch-condition.html%23

    The DO: ... END. sort of syntax is 4gl syntax -- you cannot use that in the SQL engine.