Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Query to report when item NOT found

Status
Not open for further replies.

bmacbmac

IS-IT--Management
Jan 26, 2006
392
US
Hi, I have about 10,000 numbers to search in a database of about 100,000. I can write a simple statement to search for each number indivually... like this:
Code:
 select sdocumentno 
from documentinfo 
where sdocumentno = '12345'
or sdocumentno = '12346'
or sdocumentno = '12346'

Is there a way I can get a report for all of the numbers that are not found? I'm trying to find out which of my 10,000 numbers are not in the database.

Thanks,

Brian
 
Do you have these numbers in a table?

If you did, then you could simply do a left join while checking for nulls.

Ex:

Code:
Select TableOfNumbersToSearch.Field
From   TableOfNumbersToSearch
       Left Join OriginalTable
         On TableOfNumbersToSearch.IdField = OriginalTable.IdField
Where  OriginalTable.IdField Is NULL

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
No, unfortunately I have them in a list in excel. I was just going to concatenate a statement from the list if it was the easiest way to go
 
Are your 10,000 numbers sequential?

If so, how about creating a table with all 10,000, then doing a join between that table and documentinfo so that a query returns only those records from your new table that do not have a match in documentinfo?

 
George has the right solution for you. To get an Excel list of numbers into a SQL table is easy, use the DTS Import wizard in Enterprise Manager, then use George's code
 
yep.

Open Enterprise Manager
Drill down to your database
Right Click -> All Tasks -> Import Data



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top