title: compare date with null and datetime values in sql server
body: <p>I am writing procedure in which i want to filter date using small date time from date and to date.
  from date can be null some times and To Date can also be null some time while comparing then how can i 
  filter date when the from date or to date can be null.</p>
  
  <p>I have tried following query but its giving me error.</p>
  
  <pre><code> SELECT RQ.int_REPS_QUES_DIFF_LEVEL,SUM(1) AS NoOFDificultyQuestion FROM   
   REPS_TEST_QUES_ASSIGNED RQA   
   INNER JOIN REPS_QUESTION RQ ON RQA.int_REPS_TEST_QUES_ASSG_QUESID=RQ.PK_REPS_QUES_ID  
   WHERE int_REPS_TEST_ID IN(  
   SELECT FK_TEST_ID FROM STUDENT_EXAM SE WHERE FK_USER_ID=56 AND SE.FK_REPS_BATCH_ID=466 
      and CASE 
  WHEN @FromDate!=NULL AND @ToDate!=NULL     
       THEN dat_STUD_EXAM_FINALEND &gt;= @FromDate AND dat_STUD_EXAM_FINALEND &lt;= @ToDate 
  WHEN @FromDate!=NULL AND @ToDate=NULL  
       THEN  dat_STUD_EXAM_FINALEND &gt;= @FromDate  
  WHEN @FromDate=NULL AND @ToDate!=NULL  
       THEN  dat_STUD_EXAM_FINALEND &lt;= @ToDate
  END
   )   
   strong textGROUP BY RQ.int_REPS_QUES_DIFF_LEVEL  
  </code></pre>
  
  <p>i am getting error at  </p>
  
  <pre><code>THEN dat_STUD_EXAM_FINALEND &gt;= @FromDate AND dat_STUD_EXAM_FINALEND &lt;= @ToDate  
  </code></pre>
  
  <p>this line please tell me where i am getting wrong</p>