Solved

SQL: List Days Past Due?

Posted on 2014-04-25
7
778 Views
Last Modified: 2014-04-29
I'm running a test table called SUPPLIER. It has a column called "SUPP_DUE_DATE" for when the the supplier needs to get paid for example.

I'm trying to write a query that will find the days past due from that date.

I've started on this so far:

SELECT ROUND ( (MONTHS_BETWEEN (SUPP_DUE_DATE, 'SYSDATE') * 30), 0)
          num_of_days
  FROM DUAL
GROUP BY SUPP_DUE_DATE;

Open in new window


Would something like this work?? I think this is pretty clunky..and wont work. Open to suggestions!
0
Comment
Question by:Pancake_Effect
  • 3
  • 2
  • 2
7 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40022674
'SYSDATE' is wrong, it would be SYSDATE (without the quotes)

next, instead of using months_between, you just put:
trunc(SYSDATE) - trunc(SUPP_DUE_DATE)

that will give you a number of days

I don't understand why you put GROUP BY , but let's check with above suggestion already if I "got you"?
0
 
LVL 4

Author Comment

by:Pancake_Effect
ID: 40022749
Is there a way to write this that it will only show the dates after the SUPP_DUE_DATE?

That we we don't get negative numbers if it's not the due date yet?

Using your example would it be something like this? Please correct me if I'm wrong.

SELECT TRUNC(sysdate) - TRUNC(SUPP_DUE_DATE) 
FROM SUPPLIER
WHERE SUPP_DUE_DATE < SYSDATE; 

Open in new window

0
 
LVL 31

Assisted Solution

by:awking00
awking00 earned 100 total points
ID: 40022760
select case when trunc(sysdate) <= trunc(supp_due_date) then 0
            else trunc(sysdate) - trunc(supp_due_date)
       end dayspastdue
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 400 total points
ID: 40022762
yes, that looks good, except that I would do:

SELECT TRUNC(sysdate) - TRUNC(SUPP_DUE_DATE)
FROM SUPPLIER
WHERE SUPP_DUE_DATE < TRUNC(SYSDATE);

to avoid those that are due today. if you want to include those:
SELECT TRUNC(sysdate) - TRUNC(SUPP_DUE_DATE)
FROM SUPPLIER
WHERE SUPP_DUE_DATE < TRUNC(SYSDATE) + 1;
0
 
LVL 31

Expert Comment

by:awking00
ID: 40022830
I agree. It's just that I actually posted that response before I saw the Author's comment about only showing the dates after the Supp_Due_Date.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40022842
my comment "that looks good.... " was directed to the asker, not to you, awking00
0
 
LVL 4

Author Closing Comment

by:Pancake_Effect
ID: 40029697
Worked perfectly, and in terms I understand. Thanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Via a live example, show how to take different types of Oracle backups using RMAN.

708 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

11 Experts available now in Live!

Get 1:1 Help Now