mainrotor
asked on
I need help combining two queries in SQL Server 2008
Hi experts,
I need your assistance combining the two queries below.
I need to take the sum of query #1 and subtract the sum of query #2 from it.
How can I do this? I have listed both my queries below.
NOTE: The PONUMBER field in query 1 matches the PONUMBER field in query #2.
Thanks in advance,
mrotor
I need your assistance combining the two queries below.
I need to take the sum of query #1 and subtract the sum of query #2 from it.
How can I do this? I have listed both my queries below.
NOTE: The PONUMBER field in query 1 matches the PONUMBER field in query #2.
--Query 1
SELECT
SUM(I.[QTYORDER])
FROM POPHEADER as I
inner join POPDETAIL as P
on I.PONUMBER = P.PONUMBER
where I.[POLNESTA] not in (4,5,6) and P.[DOCDATE] >= '1/1/2014' and I.[ITEMNMBR] = '209822011'
and I.POTYPE =1
--Query 2
SELECT SUM(QTYRECVD) AS QTY
FROM INVOICE_TABLE
where [DATERECD] >= '1/1/2014' and RCPTSOLD = 0
and [PONUMBER] = '07277' and [ITEMNMBR] = '209822011'
Thanks in advance,
mrotor
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ah, never mind, it looks like I misread the question.
Open in new window
But I get the feeling you are looking for something more than that, so perhaps this:Open in new window