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

Jignesh KumarRank #91 · 22.9K reputationPosted Nov 28, 2022, 7:36 AM EST
Hello,
You are missing then in Case when ?? Then Else ?? End
(case when exists (select Emp_noEligibleforSchoolFee from NSP113_EducationAllowanceMaster where Emp_ID= emp.Emp_ID ) Then "YourValuesForMatchedCondition" ELSE emp.Emp_noEligibleforSchoolFee end )Refer :
https://stackoverflow.com/questions/18099514/where-case-when-statement-with-exists
Vishal JoshiRank #377 · 6.7K reputationPosted Nov 28, 2022, 7:36 AM EST
Hello Lejo,
It looks like a case statement syntax issue. there must be Than after When condition.
Please try the below query it should work.
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 ) THEN select Emp_noEligibleforSchoolFee from NSP113_EducationAllowanceMaster where Emp_ID= emp.Emp_ID ELSE emp.Emp_noEligibleforSchoolFee END)Thanks
Aravind GovindarajRank #430 · 5.8K reputationPosted Nov 28, 2022, 7:30 AM EST
can you paste the error message pls