Hey guys,
I'm stuck on this query, and would appreciate any help. I want my query to search for two things:
People with a voucher ID ending in D
People whose first payment date in the anty_pymt table is 05-01-2010.
This code will meet the second condition:
I've tried this:
Code:
select * from dsnp.pr01_t_anty_pymt A
inner join (select a.recip_ssn_nbr, min(a.anty_Pymt_Dt) as MinDate
from dsnp.pr01_t_anty_pymt A,
dsnp.pr01_t_recip_sys B
where b.RIGHT (VOUCHER_ID_CD,1) = 'D'
group by a.recip_ssn_nbr) X
on A.recip_ssn_nbr = X.recip_ssn_nbr and
A.anty_pymt_dt = MinDate where A.anty_pymt_dt = '2010-05-01'
DB2 doesn't like the voucher id part. The query runs if I take this out. I've tried placing it outside the derived table, but still doesn't work.
Also, is there any way I can search for this criteria inside a case statement? Something like this:
Code:
sum(case When RIGHT (VOUCHER_ID_CD,1) = 'D' and MIN(B.ANTY_PYMT_DT) = '2010-05-01' then 1 end) AS "DISABILITY RETIREES",
DB2 doesn't like this code at all!