Solved

Access/SQL Comparing records against Composite Primary Key

Posted on 2016-09-19
8
68 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:Charlesdavid Allen
8 Comments
 
LVL 51

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 28

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:Charlesdavid 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 36

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
 
LVL 1

Author Comment

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

Author Comment

by:Charlesdavid 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 36

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:Charlesdavid 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

829 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