Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

How to remove the OR clause in this query?

$
0
0

Hello Everyone,

I have this query where i have a lot of joins and in the where clause there is a ISNULL and conditions based on OR clause.

How to remove the use of the OR clause which may cause performance problems? Can anyone suggest a method to remove the OR clause?


select RS.PLANNEDSTART,

OD.ESTSHIPDATE

FROM TABLE1 RS(NOLOCK)
     INNER JOIN TABLE2 SS(NOLOCK)
     ON RS.ID1             = SS.ID1
     INNER JOIN TABLE3 AM(NOLOCK)
     ON AM.KEYID        = SS.KEYID
     INNER JOIN TABLE4 OD(NOLOCK)
     ON SS.KEYID= OD.KEYID

    ...                               ...

    INNER JOIN TABLE 8 DR

   ON

      (
WHERE              (isnull(RS.DATE1,'1970-01-01 00:00:00.000') ='1970-01-01 00:00:00.000'
                 AND OD.DATE1 between @Beginning_Route_Date and @Ending_Route_Date)
             OR
             (
             RS.DATE1!='1970-01-01 00:00:00.000'
               AND RS.DATE1 BETWEEN  @Beginning_Route_Date and @Ending_Route_Date)              
            )

Regards

Gautam S


Gautam S


Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>