What am I doing wrong? OR with AND logic

  • I need help with my where clause. The criteria below works except source_ID '100' keeps showing up in my data.  Basically I have 2 OR's and 1 AND. What is the best way to use these together? Im sure I must be doing this incorrectly.

    FROM table1
    WHERE (APPLE_IND = 1 OR GRAPES_IND = 1)
    AND SOURCE_ID <> 100 OR ADDRESS <> 'NOT APPLICABLE'
  • Maybe this?

    FROM table1
    WHERE (APPLE_IND = 1 OR GRAPES_IND = 1)
    OR (SOURCE_ID <> 100 AND ADDRESS <> 'NOT APPLICABLE')

    If not, can you try putting your requirement into English?

    "Choose rows where either (this) or (this and this) is true"

    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.

  • Or maybe you need this?!:

    ...

    AND SOURCE_ID <> 100 AND ADDRESS <> 'NOT APPLICABLE'

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

Viewing 3 posts - 1 through 2 (of 2 total)

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