Solved

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

Posted on 2011-03-21
8
195 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
8 Comments
 
LVL 40

Expert Comment

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

Assisted Solution

by:8080_Diver
8080_Diver earned 200 total points
Comment Utility
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
Comment Utility
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
 
LVL 1

Expert Comment

by:vandalesm
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Author Comment

by:fabi2004
Comment Utility
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 300 total points
Comment Utility
--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
Comment Utility
Alright, I'll try that.  brb
0
 
LVL 1

Author Closing Comment

by:fabi2004
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

771 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

11 Experts available now in Live!

Get 1:1 Help Now