Home Forums SQL Server 7,2000 T-SQL Any way to clean up mutually exclusive OR conditions? RE: Any way to clean up mutually exclusive OR conditions?

  • xr280xr (9/26/2016)


    I don't specifically care about short circuiting. I just need to only evaluate b if a is false and only evaluate c if a and b are false. It's not a performance issue to me, it's the logic I need. I was only pointing out that short circuiting allows that to be written very neatly. I'm hoping for a way to write it more neatly in t-sql or confirmation that it can't be.

    A CASE expression will do this. It evaluates the subsequent conditions only if all of the preceding conditions evaluate to FALSE or UNKNOWN (NULL). The CASE expression CANNOT return a Boolean value, so generally you want to return some token (usually 'T', 'True' or 1) to indicate when the condition is true and then compare that token to the expected value.

    That being said, be very sure that you really need to evaluate them in the specified order.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA