Looking for a Query Statment

  • I have to put together a Query statement and I am looking for a way to do something with an Everything BUT, I have maybe 2000 plus unique Identifiers for a Field in a table however I only want to pull all but the following "OUT,NAB,NHB". Not really sure how to do this?

    The field in the database is called "chppon"

  • You need to use NOT IN.

    Jack Corbett
    Consultant - Straight Path Solutions
    Check out these links on how to get faster and more accurate answers:
    Forum Etiquette: How to post data/code on a forum to get the best help
    Need an Answer? Actually, No ... You Need a Question

  • can you give me an example of how to place that statement?

    Does it go in the FROM section or the WHERE section?

  • WHERE [column] not in ('x','y','z')

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Phil Parkin (3/15/2016)


    WHERE [column] not in ('x','y','z')

    So in order to Flip this Statement to True what would I change "Not in" too?

  • To remove the negation, remove the NOT. So IN.

    But Phil's code does exactly what you asked. It would return all rows except the ones that have the value of x, y or z.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Yes it worked. I just wanted to make sure incase I need to run the other direction as this query is about 12 pages long already. Working with over 300 tables and billions of records. Just looked at it so much I feel brain dead.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply