Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Exclude from query

Author  Topic 

Einar
Starting Member

2 Posts

Posted - 2008-01-09 : 13:29:12
Hi. hope someone can help me with this thing.

I have a list of numbers that I get from a query to my database. how could I make the query so that I can exclude a couple of numbers. For example the numbers 1234 and 8888. My list is in the range of 1 - 99999.

Thank you
Mr. Newbie

stowellg
Starting Member

9 Posts

Posted - 2008-01-09 : 13:34:16
I'll get crucified for this, but


--assumes its a number datatype of some sort
SELECT
theNumber
From
theTable
Where
theNumber not in (1234,8888)

--If its a range of numbers
--lists all numbers but those in the range of 1234 and 8888
--so 1-1233 shows up, and 8889-9999 shows up
SELECT
theNumber
From
theTable
Where
theNumber not between 1234 and 8888


Just a warning to beware not in, and large lists of values.


I have a stupid question for you...
Go to Top of Page
   

- Advertisement -