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!

Select rows where address is not null

Status
Not open for further replies.
May 11, 2004
37
US
Hi All, I an a newbie to SQL queries and need to select rows from a contact DB where Address, City, State, Zip aren't null. I hope I am using the right lingo. Basically, if any of those fields are blank, I don't want it. I tried using city not is null, zip not is null, etc. but the query returns tons of <NULL>s. Can someone point me in the right direction? thanks!
 
SELECT select fields, separated by commas FROM ContactDB
WHERE Address IS NOT NULL AND City IS NOT NULL AND State IS NOT NULL AND Zip IS NOT NULL

-------------------------
The trouble with doing something right the first time is that noboby appreciates how difficult it was.
- Steven Wright
 
No luck, I still get tons of <Null>s for the fields I specfied to be not null. Any ideas? Here's my code:

SELECT DISTINCT Company, Contact, Address1, Address2, City, State, Zip, Country
FROM Contact1
WHERE (COMPANY IS NOT NULL)AND(CONTACT IS NOT NULL) AND (TITLE IS NOT NULL) AND (ADDRESS1 IS NOT NULL) AND
(ADDRESS2 IS NOT NULL) AND (CITY IS NOT NULL) AND (ZIP IS NOT NULL) AND (STATE IS NOT NULL) AND
(COUNTRY = 'United States') OR
(COUNTRY = 'US') OR
(COUNTRY = 'usa') OR
(COUNTRY = 'U.S.') OR
(COUNTRY = 'u.s.a.') OR
(COUNTRY = 'U.S') OR
(COUNTRY = 'Canada')OR
(COUNTRY = 'u.s.a')
 
I believe your first OR statement after your NULL tests is causing the problem. You have a bunch of AND statements which will work fine on there own. You should wrap all the COUNTRY = tests in paranthesis. Better still, make the country test with IN.

Ex:

Code:
AND (Country IN ('united states', 'US', 'usa', 'u.s.', 'u.s.a.', 'canada')
 
I forgot to add the last parenthesis

Code:
AND (Country IN ('united states', 'US', 'usa', 'u.s.', 'u.s.a.', 'canada'))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top