Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9069

Query Help.

$
0
0

I have a query that I have pasted below.  I want the field CHGOFFAMT, which I highlighted below, to appear in the command field so that I can add the field into the report.  What am I doing wrong?

 

with actuals as (

select a.rmsfilenum, m.rmsacctnum , length(trim(m.rmsacctnum)) as acctlen, Trim(c.RMSfirstNM) || '  ' || trim(c.rmslastnm) as debtor, c.rmsstatecd,

trim(u.rmslastnm) as BCLEDesc, u.usercde2 as bcle, m.ATTRNYCODE as ATTY, r.MISDDESC as ATTYDESC, rmsdateasg,

  1. p.rmsbrglvl2,case when '{?RLSname}' = '' then '{?Affname}'  else '{?RLSname}' end as affiantname, rmslastpmt , lastpmtamt, rmsdtcontr,rmsdtchgdt,
  2. ur.county,ur.state,a.rmstrandte as reqdt,c.rmsfirstnm,c.rmslastnm,

 

      CASE WHEN RMSJDGDATE  = 0 THEN                                     

(p.RMSCHGAMT+p.RMSASSCCST+RMSACRDINT+p.UDCCOSTS1+p.UDCCOSTS2)-(RMSRCVPCPL+ 

RMSXCSRCVS+RMSRCVDCST+RMSRCVDINT+p.UDCRECCS1+p.UDCRECCS2)              

   else

(RMSJDGCHOF+RMSJDGCSTS+RMSJDGINTS+p.JDGCOSTS1+p.JDGCOSTS2)-(JDGRECVRYS+

JDGXCSRCVS+JDGRCVCSTS+JDGRCVINTS+JDGRECCS1+JDGRECCS2)              

      end as curbal        

from REPORTING.Rhistfl as a join reporting.rmaster as m on a.rmsfilenum = m.rmsfilenum left join reporting.rsasrecv as r on m.attrnycode = r.rmsrecvrcd left join reporting.rusrd2 as u on m.usercde2 = u.usercde2

left join reporting.rcomker c on a.rmsfilenum = c.rmsfilenum

left join reporting.rprdbal p on a.rmsfilenum = p.rmsfilenum

join rwagner.rfuserATTY ur

on R.MISDDESC = ur.MISDDESC

where p.rmsbrglvl2 = ur.rmsbrglvl2 

and c.recordtype = 'D'

and a.rmstrancde = 'MT' and     a.rmsfldimpl = 'LETTERNAME'

and c.RMSSTATECD  = 'NY'

and a.rmstrandte between {?strtdt}   and {?Enddt}                     

and a.hstoldvalu = 'ATTY1AFF'

and rmsstatus not like 'P%'

and  ur.username = '{?Affname}'

), 

getrecord as (

select a.*, repeat('*', acctlen - 4) || substr(a.rmsacctnum,acctlen - 3,4) as acctnum, rmstrandte as dateplaced, rmsbalance as placamt

From actuals as a left join reporting.rhistfl as h on a.rmsfilenum = h.rmsfilenum and rmstrandte = rmsdateasg and RMSTRANCDE = 'MR' And RMSFLDIMPL = 'ATTRNYCODE' and HSTNEWVALU = ATTY ),

getdistinct as (

select distinct a.* from getrecord a),

getpayments as(

select g.RMSFILENUM,

sum(case when rmstrancde between '3 ' and '39' then rmstranamt end) as costs,

sum(case when rmstrancde in ('10','18','19') then rmstranamt end) as chgoffamt

 

from getdistinct as g join reporting.rfinanl as f on g.rmsfilenum = f.rmsfilenum

where

 

rmstrancde between '3 ' and '39'

or  rmstrancde in ('10','18','19')

 

group by g.RMSFILENUM)

select g.rmsfilenum, g.rmsacctnum , g.debtor, g.BCLEDesc, g.bcle, g.ATTY, g.ATTYDESC, g.rmsdateasg, affiantname,

county,state,reqdt,rmsfirstnm,rmslastnm,

 

cast(char(g.acctnum) as char(16) ccsid 37)  as acctnum, g.dateplaced, g.placamt, rmsstatecd,case when costs is null then 0 else costs end as costs,

 

Current Date as CurDte,

RMSBRGLVL2,substr(rmsdtcontr,5,2)||'/'||substr(rmsdtcontr,7,2)||'/'||substr(rmsdtcontr,1,4) as opendate,substr(rmsdtchgdt,5,2)||'/'||substr(rmsdtchgdt,7,2)||'/'||substr(rmsdtchgdt,1,4) as chgoffdate,curbal,substr(rmslastpmt,5,2)||'/'||substr(rmslastpmt,7,2)||'/'||substr(rmslastpmt,1,4) as rmslastpmt,lastpmtamt

from getrecord as g left join getpayments as p on g.rmsfilenum = p.rmsfilenum


Viewing all articles
Browse latest Browse all 9069

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>