Solved

Oracle 10g - Modify select  CASE

Posted on 2013-06-10
2
391 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
[X]
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
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

724 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