Solved

SQL: List Days Past Due?

Posted on 2014-04-25
7
878 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
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 143

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 32

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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 143

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 32

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 143

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

627 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