IF ELSE to cause a WHERE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Evan Lepolt
    New Member
    • Jan 2012
    • 1

    IF ELSE to cause a WHERE

    What it boils down to is such:

    IF(Condition)
    WHERE Column_Name = 'x'
    ELSE
    I don't want a 'WHERE'

    I had this for a while, but it's not working the way I want due to the fact that there is no else statement:

    WHERE Column_Name = CASE
    WHEN(Condition != 'All') Then 'x' end
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    It's called conditional WHERE clause. To do what you are trying to accomplish, you have to remember that an "always true" condition is as if there's no where.

    So try something like...

    Code:
    WHERE Column_Name = case when (Condition) = True then 'x' else Column_Name end
    Now, be careful on reversing this condition and consider NULL.

    Happy Coding!!!


    ~~ CK

    Comment

    Working...