I am new to CASE statements and trying to see if there is a way to insert a select statement inside the case statement. The reason being is I have to use the min() function which requires using the HAVING CLAUSE. I can't just use a simple WHERE statement like I have with my other CASE statements. Here is the code I am trying:SELECT B.AGTY_SYS_CD, B.BENEF_STAT_CD, sum(case When (select recip_ssn_nbr from dsnp.pr01_t_recip_sys where right(B.voucher_id_cd,1) = 'D' group by A.recip_ssn_nbr having min(A.anty_pymt_dt) = '2010-05-01' ) then 1 end) AS "DISABILITY RETIREES"FROM DSNP.PR01_T_ANTY_PYMT A, DSNP.PR01_T_RECIP_SYS B WHERE A.RECIP_SSN_NBR=B.RECIP_SSN_NBRAND A.BENEF_STAT_CD IN ('AC', 'DP') AND A.RECIP_TYPE_CD = '10' AND A.BENEF_SEQ_NBR = 1 GROUP BY A.AGTY_SYS_CD, A.BENEF_STAT_CD ORDER BY 3 DESCUnfortunately, I get errors about using the reserve word THEN. I don't know if it is just a simple syntax problem or SQL can't run this type of query.