Home » SQL & PL/SQL » SQL & PL/SQL » Case in a SELECT
Case in a SELECT [message #7750] Fri, 04 July 2003 12:11 Go to next message
Katie
Messages: 3
Registered: July 2003
Junior Member
I need to create colomns in a SELECT base on certains conditions. I know I can use the DECODE function but I have conditions that conbines AND and OR and I don't know how to implement it in a DECODE statement. so I thought I would be better to use the CASE statement. The problem is that I think I cannot do it with SQL PlUS is it possible. ??

Cans somebody help me to implement it with the DECODE ?

Here is an example

SELECT DECODE(greatest(CRPDTA.F4111.ILTDAY,70000), least(CRPDTA.F4111.ILTDAY,153000), 'D',
DECODE(greatest(CRPDTA.F4111.ILTDAY,153000), least(CRPDTA.F4111.ILTDAY,230000), 'E',
DECODE(greatest(CRPDTA.F4111.ILTDAY,230000), least(CRPDTA.F4111.ILTDAY,240000), 'N',
DECODE(greatest(CRPDTA.F4111.ILTDAY,15959), least(CRPDTA.F4111.ILTDAY,70000), 'N','X')))) AS shift,
Abs(CRPDTA.F4111.ILTRQT) AS ILTRQT, CRPDTA.F4111.ILDCT, CRPDTA.F4111.ILLOCN, CRPDTA.F4111.ILFRTO,
CASE WHEN (CRPDTA.F4111.ilfrto='T' & (crpdta.f4111.ILLOCN='FAB' | crpdta.f4111.ILLOCN='FAB')) THEN Abs([[iltrqt]])
ELSE 0 END
FROM CRPDTA.F4111
WHERE (((CRPDTA.F4111.ILLOCN)='FAB' Or (CRPDTA.F4111.ILLOCN)='RECEIV') AND ((CRPDTA.F4111.ILFRTO)='T') AND ((CRPDTA.F4111.ILMCU)=' SPECTRA'));

Thanks in advance !

Katie
Re: Case in a SELECT [message #7767 is a reply to message #7750] Mon, 07 July 2003 11:24 Go to previous message
Mike T
Messages: 32
Registered: August 2002
Member
You can nest Decodes:

DECODE(CRPDTA.F4111.ilfrto,'T',DECODE(crpdta.f4111.ILLOCN,'FAB',Abs([[iltrqt]]),0),0)
Previous Topic: timestamp - HOURS ??
Next Topic: Want Logic for the Data Process
Goto Forum:
  


Current Time: Fri Apr 26 23:33:29 CDT 2024