+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Where's the beef? Scott Tiger's Avatar
    Join Date
    Mar 2002
    Location
    Southwest, VA
    Posts
    3,586

    Help with Query Needed

     
    Ok, I'm stuck. I've read what I have in front of me and Googled around but can't seem to get this.

    I'm trying to search a database that has both <NULL> values AND blank values for the same field in different records. I need to filter out both. Here's what I have so far:

    Code:
    SELECT DISTINCT DestCity 
    FROM      OppPrimary2  
    WHERE   (DestCity IS NOT NULL)  
    ORDER BY DestCity
    The problem is that the records with "blank" fields - as in empty but not <NULL> - get through this query.

    The DestCity field is a VARCHAR with a 19 character space limit. The SQL server is MS SQL Server 2000 if that matters.

    Any suggestions?
    Where's Lunch?

  2. #2
    Member cyclist110's Avatar
    Join Date
    Jun 2003
    Location
    Calgary,AB
    Posts
    176
    Try something like:

    SELECT DISTINCT DestCity
    FROM OppPrimary2
    WHERE (DestCity IS NOT NULL) OR (DestCity IS NOT "")
    ORDER BY DestCity


    IS NOT may actually be <>
    Last edited by cyclist110; June 27th, 2005 at 06:47 PM.
    C.

  3. #3
    Member
    Join Date
    Sep 2002
    Posts
    364
    You're almost right. Should be:

    Code:
    SELECT DISTINCT DestCity 
    FROM OppPrimary2 
    WHERE (DestCity IS NOT NULL) AND (DestCity <> '')
    ORDER BY DestCity
    Note the single quotes, the not equal operator, and the AND.

  4. #4
    Member cyclist110's Avatar
    Join Date
    Jun 2003
    Location
    Calgary,AB
    Posts
    176
    I think the AND will be a problem, it'll look for DestCity being not equal to NULL AND not equal to ' ', whereas using the OR says give me anything that is not equal NULL OR ' '. As for the rest I fully agree.
    C.

  5. #5
    Where's the beef? Scott Tiger's Avatar
    Join Date
    Mar 2002
    Location
    Southwest, VA
    Posts
    3,586
    Quote Originally Posted by Creosote
    You're almost right. Should be:

    Code:
    SELECT DISTINCT DestCity 
    FROM OppPrimary2 
    WHERE (DestCity IS NOT NULL) AND (DestCity <> '')
    ORDER BY DestCity
    Note the single quotes, the not equal operator, and the AND.
    This works! Thanks for the help! I really appreciate the advice.
    Where's Lunch?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help with PS2 query
    By kiwitech in forum General Gaming Discussion
    Replies: 4
    Last Post: October 9th, 2008, 06:36 PM
  2. Windows XP query
    By Doot in forum Applications and Operating Systems
    Replies: 6
    Last Post: January 2nd, 2004, 09:45 PM
  3. New Query: 1TNR-Q2
    By BitSpit in forum Distributed Computing
    Replies: 2
    Last Post: September 12th, 2003, 09:45 PM
  4. Access 97 Query
    By kickzum in forum Applications and Operating Systems
    Replies: 6
    Last Post: August 30th, 2002, 05:28 PM

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Recommended Sites: ResellerRatings Store Reviews