Compare Tables MS Access 2007

Good Afternoon All,

I have two tables in an access database.  The first table is tblCAD and the second table is tblPCR.  I am trying to compare the field in tblCAD.IncNum to tblPCR eIncNum.  The data is coming from a website.  TblCAD represents CAD dispatches from our local 9-1-1 center.  TblPCR is coming from a second website for patient care reports.  Each is stored in a seperate table in access.  The common field is IncNum.  The CAD data comes down with an incident number attached.  As the EMT completes the report he also enters the incident number as eIncNum in the tblPCR table.  I want to compare the two incident numbers.  If the incident number is in tblPCR matches the incident number in tblCAD then I know the report was completed by the EMS provider.  

I do not know if it is possible but I would also like to see the Incident Numbers in tblCAD that have no match in tblPCR.  I want to see both completed reports and uncompleted reports.  

the CAD incident number comes down as 2012-85.  The employee may or may not use the 2012.  There report may show an incident number of 85 or 2012-85.  So I am looking for this to pick up either match.  

Any help would be greatly appreciated,

Lisa
AnneYourPointIsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

colonytireDirector of TechnologyCommented:
You should be able to use Right(tablefield, 3) in your query so it uses the last 3 characters ie your example "-85" would be returned.  Info on the query can be found here:
http://office.microsoft.com/en-us/access-help/compare-two-tables-and-find-records-without-matches-HA010205132.aspx
0
AnneYourPointIsAuthor Commented:
I have tried this and it is not working for me.  It produces a query full of bad data.  The information in tblCAD does not match the information in tblPCR.
0
Jeffrey CoachmanMIS LiasonCommented:
AnneYourPointIs,
<see the Incident Numbers in tblCAD that have no match in tblPCR.>

Try the "unmatched" query wizard in Access:
Create-->Query Wizard-->Find Unmatched....
0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

DoveTailsCommented:
I obtained a query similar to the following from the EE site in the past.
I modified it to match your table names (and included an ID field):
Data in tblCAD that have no records in tblPCR:
 
SELECT tblCAD.ID, tblCAD.incnum
FROM tblCAD
LEFT JOIN tblPCR ON tblCAD.incnum = tblPCR.eIncNum
WHERE (tblPCR.eIncNum) Is Null;
================================
adding the NOT keyword shows data in tblCAD with matching records in tblPCR

SELECT tblCAD.ID, tblCAD.incnum
FROM tblCAD
LEFT JOIN tblPCR ON tblCAD.incnum = tblPCR.eIncNum
WHERE (tblPCR.eIncNum) Is Not Null;
===================================

To remove the year from your Inc number, you may have to build a query to Trim that value away.  Here's an example:

WithoutYear: Trim(Right([incNum],Len([IncNum])-InStr([IncNum],"-")))
0
AnneYourPointIsAuthor Commented:
I created two queries and applied your suggestion of Trim(right(.  I applied the two new queries to your suggestion above replacing the queries for the tables.  I get a data type mismatch.  It works fine for the tables but trimming the incident numbers down so they match on both sides and then running the query is where I get the error.  Here is what I have:

SELECT qryCADTrimIncNum.cadID, qryCADTrimIncNum.NewCADIncNum, qryCADTrimIncNum.Unit, qryPCRTrimIncNum.eCompany, qryCADTrimIncNum.IncDate
FROM qryCADTrimIncNum LEFT JOIN qryPCRTrimIncNum ON qryCADTrimIncNum.NewCADIncNum = qryPCRTrimIncNum.NewPCRincNum
WHERE (((qryPCRTrimIncNum.NewPCRincNum) Is Null));
0
DoveTailsCommented:
AnneYourPointIs,
I see what you're talking about.  I usually try to use the JOIN syntax as opposed to the NOT IN syntax because it's more efficienct. However, in this case, it may be worth considering using the NOT IN.

Here's an example (directly on the tables and by-passing the underlying queries)

SELECT * FROM tblCAD
WHERE Trim(Right([incNum],Len([IncNum])-InStr([IncNum],"-"))) NOT IN (SELECT Trim(Right([eIncNum],Len([eIncNum])-InStr([eIncNum],"-"))) FROM tblPCR);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DoveTailsCommented:
An additional point ....   I'm assuming your 'mismatch' error message is due to data existing in one table and not in the other, yet that's what you hoping to accomplish.  So using different syntax seems to be the way to go.

 Someone else here on EE with a greater understanding may be able to clarify, but that's the only reason I can see for the error.
0
Jeffrey CoachmanMIS LiasonCommented:
^
correct.

AnneYourPointIs,

Perhaps if you posted a sample of the database that exhibits this issue, it would be easier...
0
AnneYourPointIsAuthor Commented:
Ok Dove,

You have put me on the right track, and it appears that the below query is offering the data that I was looking for.  Thanks for your help!

SELECT tblCAD1.CADID, tblCAD1.IncDate, tblCAD1.CADIncNum, tblPCR1.ePCRNum, tblCAD1.IncAddress, tblCAD1.Unit, tblPCR1.eCompany, tblCAD1.Response, tblCAD1.PSAP, tblCAD1.Disp, tblCAD1.Enr, tblCAD1.Arr, tblCAD1.EnrHosp, tblCAD1.ArrHosp, tblCAD1.Clear
FROM tblCAD1 LEFT JOIN tblPCR1 ON tblCAD1.CADIncNum = tblPCR1.PCRIncNum
WHERE (((tblCAD1.IncDate)>=#2/1/2012#) AND (Not (tblCAD1.ArrHosp) Is Null));
0
DoveTailsCommented:
Excellent,

Cheers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.