IF Statement
Posted in 2004
Topics: SQL Development & Query Writing
Hi, I'm newbie on Informix RDBMS. I would like to know the equivalent syntax for the following mysql query: SELECT if(condition1,operation1,0),if(condition2,operation1,0),etc... FROM table WHERE whereclause TIA, Nicky.
Nicolas Mainczyk wrote:
> Hi,
>
> I'm newbie on Informix RDBMS.
>
> I would like to know the equivalent syntax for the following mysql query:
>
> SELECT if(condition1,operation1,0),if(condition2,operation1,0),etc... FROM
> table WHERE whereclause
You might try either the CASE expression or the DECODE function. You didn't
say which version of Informix that you are using, so I might be leading you
on a bit of a goose chase with one or both of those. I'm not positive how
long these have been available, but for a quick answer that should work with
at least a reasonably recent version of IDS, an example of the CASE
expression follows:
SELECT cust_num, cust_name,
CASE
WHEN order_total <= 100
THEN "Small"
WHEN order_total > 100 and order_total <= 200
THEN "Medium"
ELSE "Large"
END AS order_size
FROM custorders;
Both the CASE expression and the DECODE function are documented in the IBM
Informix Guide to SQL: Syntax (Version 9.4) manual. This documentation, as
well as that for older versions, can be found online. See:
http://www.ibm.com/informix/pubs/library/lists.html
--
June Hunt