title: if else condition in where clause in ms sql server
body: <p>I'm trying to retrieve the records from the joined tables based on 2 condition like below:</p>
  
  <pre><code>Where if(b.enddate is null)
           a.starttime &gt;= b.starttime
        else
           a.starttime &gt;= b.starttime and a.endtime &lt;= b.endtime
  </code></pre>
  
  <p>I have seen examples using case when but the result is not what I wanted. Please assist me to convert this condition into a proper sql format. </p>