Group:  Microsoft Access ยป microsoft.public.access.queries
Thread: Table differences

Geek News

Table differences
"brownti via AccessMonster.com" <u31540[ at ]uwe> 12/30/2008 9:50:03 PM
I get a weekly schedule sent to me in an excel file that has about 200 rows
of addresses, descriptions, and dates. In the past we have gone through last
weeks list and this weeks list to find differences. This takes way too long
for something that access can do. I have got to the point of comparing
existing records to last weeks records but not been able show new records
that were not on last weeks. Here is the SQL that i am using to compare
tables. Can anyone please help me adapt it to also show records that didnt
exist on DeliveryOld but now do on DeliveryNew and vica versa? THanks

SELECT [DeliveryNew].Address, [DeliveryNew].DeliveryDate, [DeliveryNew].
Description
FROM [DeliveryOld], [DeliveryNew]
WHERE ((([DeliveryNew].Address)=[DeliveryOld].[Address]) AND (([DeliveryNew].
DeliveryDate)<>[DeliveryOld].[DeliveryDate]) AND (([DeliveryNew].Description)
=[DeliveryOld].[Description]))
ORDER BY [DeliveryNew].Address, [DeliveryNew].DeliveryDate;

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-queries/200812/1

Re: Table differences
John W. Vinson <jvinson[ at ]STOP_SPAM.WysardOfInfo.com> 12/31/2008 5:34:08 AM
On Tue, 30 Dec 2008 21:50:03 GMT, "brownti via AccessMonster.com" <u31540[ at ]uwe>
wrote:

[Quoted Text]
>I get a weekly schedule sent to me in an excel file that has about 200 rows
>of addresses, descriptions, and dates. In the past we have gone through last
>weeks list and this weeks list to find differences. This takes way too long
>for something that access can do. I have got to the point of comparing
>existing records to last weeks records but not been able show new records
>that were not on last weeks. Here is the SQL that i am using to compare
>tables. Can anyone please help me adapt it to also show records that didnt
>exist on DeliveryOld but now do on DeliveryNew and vica versa? THanks

To do this you need a "Full Outer Join", which is not supported in Access; you
can get around this limitation by combining a Left Outer Join with a Right
Outer Join using a UNION query:

SELECT [DeliveryOld].Address, [DeliveryOld].DeliveryDate, [DeliveryOld].
Description, [DeliveryNew].Address, [DeliveryNew].DeliveryDate, [DeliveryNew].
Description
FROM [DeliveryOld] LEFT JOIN [DeliveryNew] ON
[DeliveryNew].Address=[DeliveryOld].[Address]
WHERE ([DeliveryNew].DeliveryDate<>[DeliveryOld].[DeliveryDate] OR
[DeliveryOld].[DeliveryDate] IS NULL)
AND ([DeliveryNew].Description<>[DeliveryOld].[Description] OR
[DeliveryOld].[Description] IS NULL)
UNION
SELECT [DeliveryOld].Address, [DeliveryOld].DeliveryDate, [DeliveryOld].
Description, [DeliveryNew].Address, [DeliveryNew].DeliveryDate, [DeliveryNew].
Description
FROM [DeliveryOld] RIGHT JOIN [DeliveryNew] ON
[DeliveryNew].Address=[DeliveryOld].[Address]
WHERE ([DeliveryNew].DeliveryDate<>[DeliveryOld].[DeliveryDate] OR
[DeliveryNew].[DeliveryDate] IS NULL)
AND ([DeliveryNew].Description<>[DeliveryOld].[Description] OR
[DeliveryNew].[Description] IS NULL)

This will need some tweaking I imagine; but the first query will show all
records where there is a matching address in both tables with a different
delivery date or description, or there is a record in deliveryold that
doesn't exist in deliverynew; the second SELECT will in addition show those
records that have disappeared from deliveryold. The UNION will combine them to
show all changed records.

--

John W. Vinson [MVP]

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net