?
Solved

How to search a table based on a seperate list of names.

Posted on 2011-03-21
8
Medium Priority
?
200 Views
Last Modified: 2012-08-13
I need to search a Microsoft SQL 2000 database table called Candidates for email addresses for a seperate list of names I was given.

My list has columns for First Name, Last Name, Title, Company, Address, City, State, Zip, etc.  The Candidate table has most of these fields and many others.  I believe the Company and Address information is actually in a Companies table, linked to the Candidates table.

So my first question is how do I search the table based on information from my list?  

Then, I get really confused thinking of how to make sure I'm pulling the correct information.  All I need is the email address for each name on my list.  But the database is huge, so how do I make sure I have the correct person?  I can't be sure the company name or address information will be spelled or written exactly in the database table as it is in my list.

Any help with even part of this would be greatly appreciated.  If it makes it easier or better for anyone, I can breake the question into multiple questions.

Thanks!
0
Comment
Question by:fabi2004
[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
8 Comments
 
LVL 41

Expert Comment

by:Sharath
ID: 35185427
Can you provide some sample data with expected result?
0
 
LVL 22

Assisted Solution

by:8080_Diver
8080_Diver earned 800 total points
ID: 35185439
Now you know why using "Natural Keys" such as First Name and Last Name (or even Company Name) is a bad idea. ;-)

The best you can hope for is to get as many as possible on your first pass and then to refine your results using additional approaches.  For the first pass, match as many columns as possible (which will probably mean that you will need to do some JOINs to get the data from the database).  I would then start matching fewer columns, e.g. omit the First Name column and match the rest.  (My reasoning would be Richard doesn't match Dick, Rick, or Ricky but the last name should be the same if it is the same person.)

An alternative is to go with a SoundEx search on the names . . . but that can lead to false positives when Smith, Smithe, and Smythe get matched.
0
 
LVL 1

Author Comment

by:fabi2004
ID: 35190700
8080_Diver you are way over my head.  :-)

Sharath, sample data is basic.  The table contains fields like FirstName LastName Email, and my Excel list contains fields like FirstName, LastName, etc.  I need the Email from the table based on the names on my Excel sheet.  I don't know how to query the database based on information on my list.  I don't want to type in each name individually into the code.
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 1

Expert Comment

by:vandalesm
ID: 35190846
In your Excel Spreadsheet, you can generate a serries of INSERT statements

You can copy/paste these INSERTS string into your Query Analyser and insert it into a temporary table.

You can then use the temporary table and JOIN with another table you wanted to search to.

Let me know I need to expound these.
0
 
LVL 1

Author Comment

by:fabi2004
ID: 35191040
vandalesm, thanks, that makes sense but I do need a little more detail.  Woul I create an INSERT statement for eah of the couple thousand names on my list?  Not a real big deal since I can auto fill in Excel.  I've never worked with a temp table.  I assume they're created the same as a regular table?

I was thinking along the lines of a split function I heard of once.  Something that would loop through the table for each name on my list and return the email address. Say from a csv list which is easily created from my Excel.
0
 
LVL 1

Accepted Solution

by:
vandalesm earned 1200 total points
ID: 35191163
--Create a temporary table
CREATE TABLE #names (first_name varchar(30), last_name varchar(30))

-- Then copy/paste your INSERT statement into the temporary table.

-- Search the Candidate table
SELECT c.*
FROM Candidate c
INNER JOIN #names n
ON n.first_name = c.first_name
AND n.last_name = c.last_name
0
 
LVL 1

Author Comment

by:fabi2004
ID: 35191424
Alright, I'll try that.  brb
0
 
LVL 1

Author Closing Comment

by:fabi2004
ID: 35192123
808_Diver, thank you for pointing out the diffirent iterations of joins to filter the data.

vandalesm, thanks so much.  I was looking for a different way of doing this but it turned out that creating a new table with the spreadsheet data and joining it to the database table I need to search was not as time consuming as I thought it would be.

I really appreciate everyone's time and effort.
Have a great day!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

765 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