Oracle 10g - Select based on outcome of first select

Experts,
An easy one today...

I have two working select statements. I need to combine them so that if my input variable matches the first select, I return the results of the second select. If the Variable does not match, nothing should be returned.

Please help me with the syntax

IF vQTY = (
Select 
ITEM_QTY_BKD_QTY 
from M_Item_D1 where comp_Code = 'T2' 
and Cust_Code = 'BARITEST' 
and Item_Code = '003562' 
and ITEM_QTY_BKD_LEV_NUM = 1)

select
ITEM_QTY_BKD_NUM_LAY LAYERS,
ITEM_QTY_BKD_QTY_PER_LAY QTY
from M_Item_D1 where comp_code = 'T2' 
and cust_code = 'BARITEST' 
and item_code = '003562'
and item_qty_bkd_lev_num = 1

Open in new window

LVL 1
JDCamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alexander Eßer [Alex140181]Software DeveloperCommented:
why not simply join these tables?!
0
johnsoneSenior Oracle DBACommented:
I am missing something, or is this what you are looking for:

select
ITEM_QTY_BKD_NUM_LAY LAYERS,
ITEM_QTY_BKD_QTY_PER_LAY QTY
from M_Item_D1 where comp_code = 'T2' 
and cust_code = 'BARITEST' 
and item_code = '003562'
and item_qty_bkd_lev_num = 1
and item_qty_bkd_qty = &vQTY

Open in new window


That should work in SQL*Plus and prompt for vQTY.  If you are using bound queries from some language, it would be:

select
ITEM_QTY_BKD_NUM_LAY LAYERS,
ITEM_QTY_BKD_QTY_PER_LAY QTY
from M_Item_D1 where comp_code = 'T2' 
and cust_code = 'BARITEST' 
and item_code = '003562'
and item_qty_bkd_lev_num = 1
and item_qty_bkd_qty = :1

Open in new window


Then bind vQTY to the variable.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
johnsoneSenior Oracle DBACommented:
No need to join tables, it is the same table.
0
JDCamAuthor Commented:
Wow... I was trying way too hard and looked right past the obvious.
thanks
0
Alexander Eßer [Alex140181]Software DeveloperCommented:
No need to join tables, it is the same table.

I didn't mean it that way ;-)

I was aware of that fact
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.