Solved

Aging Report in ORACLE or MSSQL

Posted on 2004-03-26
4
1,288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

726 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