Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Group and sum in Union query

Status
Not open for further replies.

Aleathiel

Technical User
May 13, 2005
21
CA
Hi, I created 2 query, one get all the qty on a pick ticket that we have stock and the other for the qty we don't have stock, I need to create a query that will combine these 2 into one and that will sum the qty if the same pick ticket appear on the 2 query, I can do it with another query that is getting info from union query but I can't figure how to do it from the union query. Could someone help me find a way to only do it in 1 query instead of 2?

here is my sql statement:
Select A.SO_NO,A.SO_STATUS,A.CUST_CODE, A.REQUEST_SHIP_DATE, A.SHIPPING_INSTR, A.SumOfQTY_ORDERED FROM [KIT TYPE C Sum Qty 2] as A
UNION Select B.* FROM [KIT TYPE P Sum Qty 2] as B;

Thanks in advance!
 
Code:
Select X.SO_NO,X.SO_STATUS,X.CUST_CODE, X.REQUEST_SHIP_DATE, X.SHIPPING_INSTR, SUM(X.SumOfQTY_ORDERED) As [Sum Ordered]

 FROM
(
Select A.SO_NO,A.SO_STATUS,A.CUST_CODE, A.REQUEST_SHIP_DATE, A.SHIPPING_INSTR, A.SumOfQTY_ORDERED FROM [KIT TYPE C Sum Qty 2] as A
UNION ALL
Select B.SO_NO,B.SO_STATUS,B.CUST_CODE, B.REQUEST_SHIP_DATE, B.SHIPPING_INSTR, B.SumOfQTY_ORDERED
FROM [KIT TYPE P Sum Qty 2] as B
) As X

Group By X.SO_NO,X.SO_STATUS,X.CUST_CODE, X.REQUEST_SHIP_DATE, X.SHIPPING_INSTR
 
Golum your a King, it worked perfectly, thanks a lot :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top