select emp.* into #TempEmpList1 from (SELECT row_number()over(partition by Emp_ID order by Emp_ID desc) rn,* from #TempEmpList) emp where emp.rn<= (case when exists (select Emp_noEligibleforSchoolFee from NSP113_EducationAllowanceMaster where Emp_ID= emp.Emp_ID ) ELSE emp.Emp_noEligibleforSchoolFee end )
BOLD PORTION IS ERROR
HOW TO CORRECT THIS WHERE CONDITION