Solved Calculation Query

Number11

Member
Local time
Today, 22:06
Joined
Jan 29, 2020
Messages
619
Hello,

I am looking to have a query total two different fields from two different queries and then subtract one from the other, its working when query 2 has data ..

SELECT Q1.[Postcode Area], [Q1].[PR1]+[Q1].[Non_PR1] AS Q1_Total, [Q2].[PR1]+[Q2].[Non_PR1] AS Q2_Total, [Q1_TOTAL]-[Q2_TOTAL] AS Q3
FROM Q1 LEFT JOIN Q2 ON Q1.[Postcode Area] = Q2.[Postcode Area];

Postcode AreaQ1_TotalQ2_TotalQ3
G83
GL75273
GU34

Looking for this output, any ideas pls?

Postcode AreaQ1_TotalQ2_TotalQ3
G83 83
GL75273
GU34 34
 
use Nz() function:

SELECT Q1.[Postcode Area], [Q1].[PR1]+[Q1].[Non_PR1] AS Q1_Total, [Q2].[PR1]+[Q2].[Non_PR1] AS Q2_Total, Nz([Q1_TOTAL],0)-Nz([Q2_TOTAL],0) AS Q3
FROM Q1 LEFT JOIN Q2 ON Q1.[Postcode Area] = Q2.[Postcode Area];
 
use Nz() function:

SELECT Q1.[Postcode Area], [Q1].[PR1]+[Q1].[Non_PR1] AS Q1_Total, [Q2].[PR1]+[Q2].[Non_PR1] AS Q2_Total, Nz([Q1_TOTAL],0)-Nz([Q2_TOTAL],0) AS Q3
FROM Q1 LEFT JOIN Q2 ON Q1.[Postcode Area] = Q2.[Postcode Area];
Thank you that works :)
 

Users who are viewing this thread

Back
Top Bottom