title: How to use If Else Condition in Where Clause in SQL Server for Date Columns?
body: <p>I want to use if else in where condition for Date Coulmns. Actually what i want to do is:</p>
  
  <p>I have a table, which having two columns, CreatedDate and LastModifiedDate. Now what i want to check in Stored Proc is:</p>
  
  <p>if LastUpdateDate is null then it will check for CreatedDate.</p>
  
  <p>Below is my query:</p>
  
  <pre><code>SELECT isnull(SSA.UpdateDateTime, 
         isnull(SSA.CreateDateTime,'')) as LastUpdateAnswerDateTime 
  from SI_SurveySiteAnswer SSA 
  WHERE SSA.UpdateDateTime IS NOT NULL
  </code></pre>
  
  <p>There are other number of table in joins i am just pasting the required query only. how can i go for the check i am totally confused. </p>
  
  <p>Please help me..</p>
  
  <p><strong>UPDATED:</strong></p>
  
  <p>I have write the below code, please confirm if it is the correct way to use If in where </p>
  
  <pre><code>SELECT isnull(SSA.UpdateDateTime,
         isnull(SSA.CreateDateTime,'')) as LastUpdateAnswerDateTime
  from SI_SurveySiteAnswer SSA 
  WHERE  SSA.UpdateDateTime = ISNULL(SSA.UpdateDateTime,SSA.CreateDateTime)
  </code></pre>
  
  <p>I think i was not able to make my requirement very clear in first go, let me explain here..</p>
  
  <p>i have a survey question answer table, i want to send an email notification if question has been answered, now answer can answered in one go, in that case createddate will have value not the updateddatetime, 
  Second case is:
  answer is being updated in second go, then i need to check for the LastUpdateDateTime..</p>
  
  <p>That's what i want to make in query.</p>