Re: if-then-else expression in SELECT list

From: ashok kapur <akapur_at_thomtech.com>
Date: 1996/07/31
Message-ID: <31FFD956.4262_at_thomtech.com>#1/1


Bill Duttweiler wrote:
>
> Using ACCESS/ODBC/JET I can use the 'iif()'
> function in a SELECT list to do an if-then-else
> test. I've tried using the ORACLE DECODE()
> expression, but it doesn't allow conditions. For
> example,
>
> DECODE(A = B, TRUE, <true reuslt>, <false result>)
>
> gives an error like "missing right parenthesis".
> It just doesn't appear that DECODE() can handle
> condition expressions.
>
> Is there any way to do an if-then-else expression?
>
> Thanks.
>
> Bill

You can perform equality conditions using DECODE.

DECODE works as follows:
DECODE(<column_name>, [<value>,<result>], <default>)

where <colunmn_name> is the name of the column
      <value> is one of the values the column can have
      <result> is the column name has that <value> then the decode
               stmt. will return <result>
      <default> is returned when the column_name's values does not
                match any of te given <vale>s.

DECODE for IF (A='B') THEN 'C' ELSE 'D' is:
      DECODE(A, 'B', 'C', 'D')
   
-- 
Ashok Kapur (akapur_at_thomtech.com)
Thomson Technology Consulting Group
1375 Piccard Drive, Suite 250
Rockville, MD 20850
Received on Wed Jul 31 1996 - 00:00:00 CEST

Original text of this message