Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL: List Days Past Due?

Posted on 2014-04-25
7
Medium Priority
?
945 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 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 400 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1600 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Suggested Courses

783 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