I am writing a procedure in which I want to filter the date using a short time from the date to the date. from the date can be null several times, and To Date can also be null for a while when comparing, then how can I filter date when the date or date can be empty.
I tried the following query, but it gave me an error.
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 >= @FromDate AND dat_STUD_EXAM_FINALEND <= @ToDate WHEN @FromDate!=NULL AND @ToDate=NULL THEN dat_STUD_EXAM_FINALEND >= @FromDate WHEN @FromDate=NULL AND @ToDate!=NULL THEN dat_STUD_EXAM_FINALEND <= @ToDate END ) strong textGROUP BY RQ.int_REPS_QUES_DIFF_LEVEL
I get an error when
THEN dat_STUD_EXAM_FINALEND >= @FromDate AND dat_STUD_EXAM_FINALEND <= @ToDate
this line please tell me where am i wrong
source share