Solved

Aging Report in ORACLE or MSSQL

Posted on 2004-03-26
4
1,228 Views
Last Modified: 2012-05-04
Hi all,

I have a bit of a scenario for which I'd really appreciate some help.

I have a database that has client invoices that are churned out on a monthly basis, clients pay against these invoices. However, some clients sometimes don't pay or pay less than the invoiced amounts, some still, pre-pay.

Now, I need to do a debtors aging report showing the distrubution of debts between today (current) and over120 days. I'm able to pull out all my invoiced amounts correctly to allocate them to the correct time bands (30days, 60days, 90days, 120days and over120) but I keep getting errors when it comes to over120 days payments.

Any chance someone has the English query for aging so that I could adapt it to either Oracle or SQL?

Any help offered most appreciated!

Regards,
Gezzat
0
Comment
Question by:Gezzat
4 Comments
 
LVL 2

Accepted Solution

by:
aabbas earned 500 total points
ID: 10693732
Oracle's DECODE function will do this. Following is a simple query to age amount in <30, >=30, >=60, >=90, >=120 days.

select invoice_no, invoice_date, floor (sysdate - invoice_date) "DAYS",
       decode (floor (floor (sysdate - invoice_date) / 30), 0, amt, null) "<30",
       decode (floor (floor (sysdate - invoice_date) / 30), 1, amt, null) ">=30",
       decode (floor (floor (sysdate - invoice_date) / 30), 2, amt, null) ">=60",
       decode (floor (floor (sysdate - invoice_date) / 30), 3, amt, null) ">=90",
       decode (floor (floor (sysdate - invoice_date) / 30), 4, amt, null) ">=120"
from inv;

Above query uses a simple table with Invoice_No, Invoice_Date and Amt columns.

Try it out. Hope, it will work for you.

Best of luck.
0
 

Author Comment

by:Gezzat
ID: 10695020
Thanks Abbas! lemmie try this and get back to you!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Read about achieving the basic levels of HRIS security in the workplace.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now