Removing negative condition

  • how to avoid negative condition checking like 'not in', 'not like', '<>', 'not exist' in a sql query.

    For eg.

    Select * from Employee where Empid<>'10001'.

  • If you want to avoid negative condition, go the postive way... I quite dint understand what your requirement is! The question is too vague, friend! Please be more specific!

    😎

  • There is no easy way to remove a negative condition. It depends on the data in the table and the indexes. Try converting the query using a positive condition as ColdCoffee suggested and as you should be doing always TEST. If you find the positive query performing better, you have succeeded. Otherwise try again.

    And one more thing, there is no hard and fast rule that you should avoid negative conditions. Its just a suggestion. Sometimes you just can't avoid them and sometimes its better you don't avoid them. Take a decision based on the scenario and the test results.


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

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

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