dbTalk Databases Forums  

SELECT with IF THEN ELSE

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss SELECT with IF THEN ELSE in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
WebTracer
 
Posts: n/a

Default SELECT with IF THEN ELSE - 12-20-2004 , 11:45 AM






Is it possible to embed an IF - THEN - ELSE statement INSIDE of a
SELECT statement?


Reply With Quote
  #2  
Old   
Michel Cadot
 
Posts: n/a

Default Re: SELECT with IF THEN ELSE - 12-20-2004 , 12:03 PM







"WebTracer" <randy (AT) webtracersolutions (DOT) com> a écrit dans le message de
news:1103564748.483917.57380 (AT) z14g2000cwz (DOT) googlegroups.com...
Quote:
Is it possible to embed an IF - THEN - ELSE statement INSIDE of a
SELECT statement?

Have a look at CASE:

http://download-west.oracle.com/docs...5a.htm#1033394

Regards
Michel Cadot




Reply With Quote
  #3  
Old   
WebTracer
 
Posts: n/a

Default Re: SELECT with IF THEN ELSE - 12-20-2004 , 12:14 PM



Thanks. Can't seem to get this to work:

SELECT SELECT_FROM_PART, SUM(QTY_DUE), CASE SUBSTR(REQUEST_ID,1,1) WHEN
!= 'I' THEN SUBSTR (REQUEST_ID,3,4) ELSE NULL END, NEED_DATE,
REQUEST_ID
FROM REQ1
WHERE STATUS IN ('O','H')
AND (SELECT_FROM_SC LIKE '1ASL%' OR SELECT_FROM_SC = 'LASR')
GROUP BY SELECT_FROM_PART, SUBSTR (REQUEST_ID,3,4), NEED_DATE,
REQUEST_ID
ORDER BY SELECT_FROM_PART

Doesn't like != 'I' ... why is that?


Reply With Quote
  #4  
Old   
WebTracer
 
Posts: n/a

Default Re: SELECT with IF THEN ELSE - 12-20-2004 , 12:18 PM



NM ... I think I figured it out ... it has something to do with the
lack of the ELSE, right?


Reply With Quote
  #5  
Old   
WebTracer
 
Posts: n/a

Default Re: SELECT with IF THEN ELSE - 12-20-2004 , 12:23 PM



Never Mind Again. Firgured it out - like this:

SELECT SELECT_FROM_PART, SUM(QTY_DUE), CASE SUBSTR(REQUEST_ID,1,1) WHEN
'I' THEN 'Internal' ELSE SUBSTR (REQUEST_ID,3,4) END, NEED_DATE,
REQUEST_ID
FROM REQ1
WHERE STATUS IN ('O','H')
AND (SELECT_FROM_SC LIKE '1ASL%' OR SELECT_FROM_SC = 'LASR')
GROUP BY SELECT_FROM_PART, SUBSTR (REQUEST_ID,3,4), NEED_DATE,
REQUEST_ID
ORDER BY SELECT_FROM_PART

Merci Michel Cadot, Merci.


Reply With Quote
  #6  
Old   
Thomas Kyte
 
Posts: n/a

Default Re: SELECT with IF THEN ELSE - 12-20-2004 , 12:25 PM



In article <1103566487.843697.97680 (AT) c13g2000cwb (DOT) googlegroups.com>, WebTracer
says...
Quote:
Thanks. Can't seem to get this to work:

SELECT SELECT_FROM_PART, SUM(QTY_DUE), CASE SUBSTR(REQUEST_ID,1,1) WHEN
!= 'I' THEN SUBSTR (REQUEST_ID,3,4) ELSE NULL END, NEED_DATE,
REQUEST_ID
FROM REQ1
WHERE STATUS IN ('O','H')
AND (SELECT_FROM_SC LIKE '1ASL%' OR SELECT_FROM_SC = 'LASR')
GROUP BY SELECT_FROM_PART, SUBSTR (REQUEST_ID,3,4), NEED_DATE,
REQUEST_ID
ORDER BY SELECT_FROM_PART

Doesn't like != 'I' ... why is that?

case when substr(request_id,1,1) <> 'I'
then substr(request_id,3,4)
else null
end

or

decode(substr(request_id,1,1),'I',null,substr(requ est_id,3,4))


--
Thomas Kyte
Oracle Public Sector
http://asktom.oracle.com/
opinions are my own and may not reflect those of Oracle Corporation


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.