Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Oracle 10g - Modify select  CASE

Posted on 2013-06-10
2
389 Views
Last Modified: 2013-06-10
Experts,

I want to modify the query below.

Current behaviour:
SELECT PROBILL from TABLE A
IF PROBILL is NULL  SELECT MIN value from TABLEB

I have found that sometimes TABLEB is also NULL. If so, I want to return :Ordnum from the input.

SELECT CASE 
  WHEN PROBILL IS NULL
  THEN
    (Select MIN(myvalue) 
    From TABLEB 
    WHERE ORD_NUM = :Ordnum
    and COMP_CODE = :Comp)
  ELSE PROBILL
  END
FROM (SELECT MIN(WAY_BILL_NUM) PROBILL
  FROM TABLEA
  WHERE ORD_NUM = :Ordnum
  and COMP_CODE = :Comp)

Open in new window

0
Comment
Question by:JDCam
2 Comments
 
LVL 22

Accepted Solution

by:
Thomasian earned 500 total points
ID: 39235032
SELECT	COALESCE(T1.PROBILL,T2.PROBILL,:Ordnum)
FROM
	(SELECT	MIN(WAY_BILL_NUM) PROBILL
	FROM	TABLEA
	WHERE	ORD_NUM = :Ordnum
		AND COMP_CODE = :Comp
	) T1 CROSS JOIN
	(SELECT	MIN(myvalue) PROBILL
	FROM	TABLEB 
	WHERE	ORD_NUM = :Ordnum
	AND	COMP_CODE = :Comp
	) T2

Open in new window

0
 

Author Closing Comment

by:JDCam
ID: 39235058
Excellent .... Works Great
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question