select
  x.ssbat2,
  case when x.sdcd = 31 then to_char(x.ssmon2, 'yyyy/mm/dd')
    else to_char(add_months(x.ssmon2 + x.sdcd, -1), 'yyyy/mm/dd')
  end ssdat2
from (
  select ssbat2,ssmon2,sdcd
  from axm99
  where ktktcd=:ktktcd
) x
