A
Alaa
I have query which collects the total expenses and income per month from two
tables which works fine, now I want to add a third table to collect the total
payroll per month: here is my query and when I try to run it it gives me the
error:"Data type mismatch in the criteria expression"
Query:
SELECT DatePart('m', Date2) AS MDate, SUM(IncAmount) AS TInc,
SUM(ExpAmount) AS TExp, SUM(PayAmount) AS TPay
FROM [SELECT I.IncDate AS Date2,I.Amount AS IncAmount,null AS
ExpAmount,null AS PayAmount FROM Income I WHERE I.IncDate BETWEEN
#1/Jul/2007# AND #30/Jun/2008#
UNION ALL SELECT E.ExpDate AS Date2,null AS IncAmount,E.Amount AS
ExpAmount,null AS PayAmount FROM Expenses E WHERE E.ExpDate BETWEEN
#1/Jul/2007# AND #30/Jun/2008#
UNION ALL SELECT P.PayDate AS Date2,null AS IncAmount,null AS
ExpAmount,P.Net AS PayAmount FROM Payroll P WHERE P.PayDate BETWEEN
#1/Jul/2007# AND #30/Jun/2008#
]. AS U
GROUP BY DatePart('m', Date2)
ORDER BY DatePart('m', Date2)
============
As I said, if you include only 2 tables , the query will run with no
problem, but as soon as I add the third table, it shows the above error.
Much appreciated for any help to solve my problem.
tables which works fine, now I want to add a third table to collect the total
payroll per month: here is my query and when I try to run it it gives me the
error:"Data type mismatch in the criteria expression"
Query:
SELECT DatePart('m', Date2) AS MDate, SUM(IncAmount) AS TInc,
SUM(ExpAmount) AS TExp, SUM(PayAmount) AS TPay
FROM [SELECT I.IncDate AS Date2,I.Amount AS IncAmount,null AS
ExpAmount,null AS PayAmount FROM Income I WHERE I.IncDate BETWEEN
#1/Jul/2007# AND #30/Jun/2008#
UNION ALL SELECT E.ExpDate AS Date2,null AS IncAmount,E.Amount AS
ExpAmount,null AS PayAmount FROM Expenses E WHERE E.ExpDate BETWEEN
#1/Jul/2007# AND #30/Jun/2008#
UNION ALL SELECT P.PayDate AS Date2,null AS IncAmount,null AS
ExpAmount,P.Net AS PayAmount FROM Payroll P WHERE P.PayDate BETWEEN
#1/Jul/2007# AND #30/Jun/2008#
]. AS U
GROUP BY DatePart('m', Date2)
ORDER BY DatePart('m', Date2)
============
As I said, if you include only 2 tables , the query will run with no
problem, but as soon as I add the third table, it shows the above error.
Much appreciated for any help to solve my problem.