Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
if(a.WH_NO=b.WH_NO)

SELECT a.PRODUCT_NO,b.PRODUCT_NAME,a.QTY_IN,b.QTY_OUT,a.UNIT_COST FROM STOCKDETAILS a, STOCKDETAILS b WHERE a.PRODUCT_NO=b.PRODUCT_NO and a.WH_NO='WH1' AND a.STOCK_JR='IN' AND b.STOCK_JR='OU'

if(a.WH_NO!=b.WH_NO)

SELECT a.PRODUCT_NO,b.PRODUCT_NAME,a.QTY_IN,a.UNIT_COST FROM STOCKDETAILS a, STOCKDETAILS b WHERE a.PRODUCT_NO=b.PRODUCT_NO and a.WH_NO='WH1' AND a.STOCK_JR='IN' AND b.STOCK_JR='OU'

i want these queries execute at single result set
Posted
Comments
navya chowdary 11-Oct-14 6:26am    
plzzzzzzzzzzzzzz help me..
CHill60 11-Oct-14 6:28am    
Comments like this do not encourage people to help. The word is "please" and you only posted your question a few moments ago

1 solution

Firstly to get these into a single result set you need both queries to return the same number of columns in the result.

CASE [^]is the construct you need, not IF

Try this (untested)
SQL
SELECT a.PRODUCT_NO,b.PRODUCT_NAME,a.QTY_IN,
QTY_OUT = CASE WHEN a.WH_NO=b.WH_NO THEN b.QTY_OUT ELSE 0 END
,a.UNIT_COST
FROM STOCKDETAILS a,
INNER JOIN STOCKDETAILS b ON a.PRODUCT_NO=b.PRODUCT_NO AND b.STOCK_JR='OU'
WHERE a.WH_NO='WH1' AND a.STOCK_JR='IN'
 
Share this answer
 
v2
Comments
navya chowdary 11-Oct-14 7:02am    
thank u...
[no name] 11-Oct-14 7:45am    
If it helped: There is a button to accept and also you can vote a 5...same I voted ;)
CHill60 11-Oct-14 7:47am    
Thank you!
navya chowdary 11-Oct-14 8:06am    
can you write this another way if it is possible
CHill60 11-Oct-14 8:18am    
What other way were you thinking of? Why?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900