Les Isaacs
Registered User.
- Local time
- Today, 14:47
- Joined
- May 6, 2008
- Messages
- 186
Hi All (and MSAccessRookie in particular
)
This is a re-post of a thread I started yesterday, but which is presumably one of many that have been lost due to a power outage at the site's data centre.
The problem was that I have 2 tables [live] and [proposed] that have identical fields, but with no key field, and I need a report that will return any records that either
I'd had a reply (from MSAccessRookie) suggesting a union query is the way to go, so I now have:
This runs, and almost works, but where records exist in either of the tables but not the other the above query returns nulls in the 'employee' and 'period' fields (with the 'pay', 'tax' and 'NIC' values from whichever table has the record).
I must be close - but can't seem to get this right
Thanks for any further help.
Les
This is a re-post of a thread I started yesterday, but which is presumably one of many that have been lost due to a power outage at the site's data centre.
The problem was that I have 2 tables [live] and [proposed] that have identical fields, but with no key field, and I need a report that will return any records that either
- are in [live] but not in [proposed], or
- are in [proposed] but not in [live], or
- are in both tables, but with different values in field 'pay' or 'tax' or'NIC'
I'd had a reply (from MSAccessRookie) suggesting a union query is the way to go, so I now have:
Code:
SELECT proposed.employee, proposed.period, live.pay, live.tax, live.NIC
FROM live LEFT JOIN proposed ON (live.period = proposed.period) AND (live.employee = proposed.employee)
WHERE (((proposed.employee) Is Null) AND ((proposed.period) Is Null))
UNION ALL
SELECT live.employee, live.period, proposed.pay, proposed.tax, proposed.NIC
FROM live RIGHT JOIN proposed ON (live.employee = proposed.employee) AND (live.period = proposed.period)
WHERE (((live.employee) Is Null) AND ((live.period) Is Null))
UNION ALL
SELECT proposed.employee, proposed.period, [proposed].[pay]-[live].[pay] AS PayDif, [proposed].[tax]-[live].[tax] AS TaxDif, [proposed].[NIC]-[live].[NIC] AS NICDif
FROM live INNER JOIN proposed ON (live.employee = proposed.employee) AND (live.period = proposed.period)
WHERE (((live.pay)<>[proposed].[pay])) OR (((live.tax)<>[proposed].[tax])) OR (((live.NIC)<>[proposed].[NIC]));
This runs, and almost works, but where records exist in either of the tables but not the other the above query returns nulls in the 'employee' and 'period' fields (with the 'pay', 'tax' and 'NIC' values from whichever table has the record).
I must be close - but can't seem to get this right
Thanks for any further help.
Les