?
Solved

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

Posted on 2011-03-21
8
Medium Priority
?
201 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

650 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