Click here to Skip to main content
15,913,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying this select query

SQL
select sum(Recp_Qty - Issd_Qty) as AJob_av
 from Reciepts where JobNo != 'stk'
 group by IT_Name

 Union

 select sum(Recp_Qty - Issd_Qty) as AStk_av
 from Reciepts where JobNo = 'stk'
 group by IT_Name


this is giving output in this format

VB
AJob_av
5
8
10
12
15



but i want to display in below format
VB
AJob_av    AStk_av
5           0
12          0
15          0
0           8
0           10


how can i do that?
Posted

Just drop the union, and bracket your select statements:
SQL
select 
(select sum(Recp_Qty - Issd_Qty) 
 from Reciepts where JobNo != 'stk'
 group by IT_Name) as AJob_av,
(select sum(Recp_Qty - Issd_Qty)
 from Reciepts where JobNo = 'stk'
 group by IT_Name) as AStk_av
 
Share this answer
 
v2
Comments
Manzoor Ahmed P 20-Nov-13 5:59am    
Nick Fisher

this was the error when i tried!

Subquery returned more than 1 value. This is not permitted when the subquery follows =
SQL
select sum(Recp_Qty - Issd_Qty) as AJob_av, 0 as AStk_av
 from Reciepts where JobNo != 'stk'
 group by IT_Name

UNION 

select 0 as AJob_av,sum(Recp_Qty - Issd_Qty) as AStk_av
 from Reciepts where JobNo = 'stk'
 group by IT_Name
 
Share this answer
 

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