Solved

Access/SQL Comparing records against Composite Primary Key

Posted on 2016-09-19
8
64 Views
Last Modified: 2016-09-25
I have a table in SQL Server with a number of fields, i have created a composite PK of LoanNumber, BorrowerName, LenderNumber; I need to compare a new data set that contains these and other fields to determine if there are any new PK on the new data set, which will then be added to the original table.

Thank you!



Keyword Tags:
VBA, SQL, SQL Server, Access, VB
0
Comment
Question by:C Allen
8 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 41804524
>>I need to compare a new data set that contains these and other fields to determine if there are any new PK on the new data set, which will then be added to the original table.

first, where you want to compare these records? in Ms SQL Server,Access, etc? reason being there are different approaches we can do this.
0
 
LVL 24

Expert Comment

by:Pawan Kumar
ID: 41804617
Then you can use LEFT JOIN with the two table to get the new records.


Which DB you are referring ? SQL Server ?
0
 
LVL 1

Author Comment

by:C Allen
ID: 41804676
comparing access table (comma delimited, imported, error checked and formated) in code. has same field names but no PK as the SQL Server table (ODBC Linked).
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 41805125
Although joining the Access table to the SQL Server table is possible, it is inefficient since Access will send a request to download the ENTIRE SQL Server table and perform the join locally.  If the SQL Server table isn't large, then it won't be a problem but once you get to more than 100,000, you probably want to do something different.  Uploading the Access data to a temp table in SQL Server might prove to be more efficient if the Access table is very small and the server side table is very large.  Then you can do the left join in SQL Server.

The left join will return the "new" records.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 1

Author Comment

by:C Allen
ID: 41805309
left join on each field = corresponding field?
0
 
LVL 1

Author Comment

by:C Allen
ID: 41805321
Pat that is to say,

Loaded the access able to a temp table in SQL called tempNewLoandata

SELECT *
FROM tempNewLoanData
LEFT JOIN MasterLoanData
ON tempNewLoanData.LoanNumber = MasterLoanData.LoanNumber AND   tempNewLoanData.BorrowerName = MasterLoanData.BorrowerName AND tempNewLoanData.LenderNumber = MasterLoanData.LenderNumber

?
0
 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
ID: 41805335
SELECT *
FROM tempNewLoanData
LEFT JOIN MasterLoanData
ON tempNewLoanData.LoanNumber = MasterLoanData.LoanNumber AND   tempNewLoanData.BorrowerName = MasterLoanData.BorrowerName AND tempNewLoanData.LenderNumber = MasterLoanData.LenderNumber

WHERE MasterLoanData.UniqueID Is Null;

You need a where clause.  If you don't have an autonumber PK, then just use one of the join fields instead.
1
 
LVL 1

Author Closing Comment

by:C Allen
ID: 41815040
Thanks for the hand as always Pat.  Worked well; My brain was not firing on all cylinders that morning.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Viewers will learn how the fundamental information of how to create a table.

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now