I am trying to write a query to define customers who need to be placed on hold as well as taken off hold. My criteria are as follows:
To Place On Hold
-
Customer should not currently be on hold
-
If customer is over their credit limit or past their terms place them on hold
To Remove From Hold
-
Customer should be on hold
-
If customer is not over credit limit AND customer is within his terms remove the hold
I have a query written for both of these but it seems like I am missing something. Would anyone be willing to take a shot at it? I think the placing customer on hold is the easiest, but the taking them off is where I feel I am having an issue. This is the query I have written for placing customer on hold:
select
case
when
d.custblnc>a.crlmtamt then 'Credit Limit'
when
c.duedate < (getdate()+(b.duedtds+duegrper)) then 'Terms Exceeded'
when
((d.custblnc>a.crlmtamt) or ((c.duedate < (getdate()+(b.duedtds+duegrper))))) then 'Terms Exceeded/Credit Limit' end as 'Trigger',
a
.custnmbr, a.custname, case when a.hold='0' then 'No' else 'Yes'end as 'On_Hold', a.pymtrmid, b. duedtds, a.duegrper, d.custblnc, a.crlmtamt, d.avdtplif, d.avgdtpyr, d.lastpydt, d.lsttrxdt, d.ttlslytd, d.ttlslltd, d.agperamt_1 as 'Current', d.agperamt_2 as '31_45', d.agperamt_3 as '46_60', d.agperamt_4 as '61-90', sum(d.agperamt_5 + d.agperamt_6 + d.agperamt_7) as '90+' from rm00101 a
left
join sy03300 b
on
a.pymtrmid=b.pymtrmid
join
rm20101 c
on
a.custnmbr=c.custnmbr
and
c.duedate = ( Select max(i.duedate ) from rm20101 i where i.custnmbr=c.custnmbr and docnumbr like 'i%' ) --check and see if this is correct for docnumbr
join
rm00103 d
on
a.custnmbr= d.custnmbr
where
((c.duedate < (getdate()+(b.duedtds+duegrper))) or (d.custblnc>a.crlmtamt)) and a.hold='0' and a.pymtrmid<>'hard hold'
group
by c.duedate, a.custnmbr, a.custname, a.hold, a.pymtrmid, b. duedtds, a.duegrper, d.custblnc, a.crlmtamt, d.avdtplif, d.avgdtpyr, d.lastpydt, d.lsttrxdt, d.ttlslytd, d.ttlslltd, d.agperamt_1, d.agperamt_2, d.agperamt_3, d.agperamt_4, d.agperamt_5, d.agperamt_6, d.agperamt_7
order
by a.custnmbr
*This post is locked for comments
I have the same question (0)