Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PAYMENTS looks like this:
- BEN12, FLY, 8.00
- BEN12, CAR, 2.00
- MKE10, FLY, 3.00
- and Applicaitons needs to look like this:
- BEN12, 1234-10,5.00
- BEN12, 1234-11,3.00
- BEN12, 2234-20,2.00
- MKE10, 1234-13,3.00
- `declare @currentCust varchar(20) =''
- declare @LastCust varchar(20) =''
- declare @AmtBal decimal (5,2) ='50'
- declare @applyBal decimal (5,2) ='0'
- declare @CurrentDoc varchar(20) =''
- declare @LastDoc varchar(20) =''
- declare @CurrentCod varchar(20) =''
- declare @LastCod varchar(20) =''
- begin
- UPDATE USER_PRD_APPLY
- set CODE = DOCS.DED,
- @CurrentDoc = DOCS.doc_NO,
- @currentCust = DOCS.CUST_NO,
- @CurrentCod = DOCS.DED,
- CUST_ID = DOCS.CUST_NO,
- @AmtBal = case when @currentCust = @LastCust THEN @AmtBal ELSE RCV.AMT END,
- @applyBal = case
- WHEN DOCS.DED = '608' and DOCS.balance <= @AmtBal
- THEN DOCS.balance
- when DOCS.DED = '608' and DOCS.balance > @AmtBal
- THEN @AmtBal
- @LastCust= DOCS.CUST_NO,
- @AmtBal = @AmtBal- @applyBal
- from DOCUMENTS DOCS left join RECEIVE RCV
- on DOCS.CUST_NO = RCV.CUST_ID and DOCS.DED = RCV.CODE
- end
Add Comment
Please, Sign In to add comment