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?

  • In a Where clause you may have a situation as

    WHERE (a>20) OR

    (b>30 and a<=20) OR

    (c>40 and b<=30 and a<=20)

    The query optimizer can find a parallel process to run these in an efficient fashion if you have an index per column here. Turning these into Union All statements will result into three scans ,not desirable if you do not have the proper indexing.

    In your example, using a || !a & b || ...

    your !a can be represented as a=0 (implying false) to make it SARGable. Without more knowledge as to your data types and actual data this is all I can offer at the moment.

    ----------------------------------------------------