Solved

Access Query

Posted on 2009-05-06
3
151 Views
Last Modified: 2013-11-29
Hi guys,  

I am pretty new to access and have a question which I will try to explain and hope it makes sense. I'll give a bit of background as to what im doing and what my issue is.

BACKGROUND - I have a source system which is a seperate access database which is my 'source' system.  I have a seperate access database which daily runs a query against the source system and populates it to a table in my application called tblAud_Current.  I then compare tblAud_Current to tblAud_Compare (this is yesterdays data) and any changes i identify by using the primary key and then verifying each individual field and that they match.  This seems to be working ok. If they dont match it inserts the old and new value into tblAud_logs

ISSUE - The issue that I have is getting my extract of source data so as that there are only 1 unique record to be able to compare.  In the source system there is a table called tblContract.  This contains fields such as name, address, contractno, mailaddress etc.   There is another table called tblContractRate which contains fields such as contractno (this is the link field) ,ratefrom, rateto .  This table could contain more than one rate for a contract  e.g for 2007, 2008 and 2009.  This is where my problem is because when I do the join I end up getting mulitple records in my tblCurrent.  Then when I compare it will show that the records have changed yet they may not have. If i dont extract the contract rate I have no issues

I have below copied my query which is to get the data out of the source and insert it into the tblAud_Current table.

I have then copied example code which compares the field Customer Name... I have one of these queries for each field I need to check.

I have attached result of the query (selected only first 20 records) and as you can see my problem of mulitple records due to the rates issue.

I am sorry if this is extremely long I have been stuck on this for quite some time and have no way forward.  I am more than happy for any suggestions even if it means changing my approach.

Thanks heaps assistance greatly appreciated. Please let me know if this isnt clear or you need it simplified or more specific detail.

Thanks all.
Scott


EXTRACT QUERY....
 
INSERT INTO tblAud_Current ( ContractNo, MIRN, CustName, ServiceAddress, ContractStartDate, ContractEndDate, DeenergDate, MailAddress, RateFrom, RateTo, ContractPeakRate, DefaultTariffId, Phone1, Phone2 )
SELECT tblContract.ContractNo, tblMIRN.MIRN, tblContract.CustName, tblMIRN.ServiceAddress, tblContract.ContractStartDate, tblContract.ContractEndDate, tblContract.DeenergDate, [MailAddress1] & " " & [MailAddress2] & " " & [MailLocality] & " " & [MailState] & " " & [MailPostcode] AS MailAddress, tblContractRate.RateFrom, tblContractRate.RateTo, tblContractRate.ContractPeakRate, tblContract.DefaultTariffId, tblContract.PhoneNo_1 AS Phone1, tblContract.PhoneNo_2 AS Phone2
FROM ((tblContract INNER JOIN tblContractMIRN ON tblContract.ContractNo = tblContractMIRN.ContractNo) INNER JOIN tblMIRN ON tblContractMIRN.MIRN = tblMIRN.MIRN) INNER JOIN tblContractRate ON tblContract.ContractNo = tblContractRate.ContractNo
WHERE (((tblContract.DeenergDate) Is Null));
 
 
EXAMPLE COMPARE QUERY.....
 
INSERT INTO tblAud_Logs ( MIRN, OLD_VALUE, NEW_VALUE, FIELD_MODIFIED )
SELECT tblAud_Compare.MIRN, tblAud_Compare.CustName AS OLD_VALUE, tblAud_Current.CustName AS NEW_VALUE, 'Customer Name' AS FIELD_MODIFIED
FROM tblAud_Compare LEFT JOIN tblAud_Current ON tblAud_Compare.MIRN = tblAud_Current.MIRN
WHERE ((( tblAud_Compare.CustName)<>[tblAud_Current].[CustName]) OR (tblAud_Compare.CustName IS NULL AND tblAud_Current.CustName IS NOT NULL) OR (tblAud_Compare.CustName IS NOT NULL AND tblAud_Current.CustName IS NULL));

Open in new window

0
Comment
Question by:Scotty24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
pcelba earned 250 total points
ID: 24315218
This simply means you have to process the tblContractRate table as standalone subject. Suppose it should be easy because it has its own primary key.

BTW, wouldn't it be better to store data on SQL Server and create triggers to audit all changes?
0
 

Author Comment

by:Scotty24
ID: 24320755
Hi pcelba,  definately agree that this would be better done on SQL server or even in the 'source' database but the political issues in my area to make any changes there or use SQL server make it almost impossible to get it going. The access database is a very short term 'interim solution'

If I process the tblContractRate seperately will i not end up with the same issue because one contract can have more than one rate?
0
 
LVL 42

Expert Comment

by:pcelba
ID: 24343109
If you process the tblContractRate seperately (means no join to tblContract) it will be OK.  The ContarctNo in tblContractRate will be processed without any relation to tblContract and no record "multiplication" can occur.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Win 10 Automation Error with .doCmd in Access 2 30
SQL query 7 20
Estimating my database size 7 19
Access lists formating 8 8
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question