Solved

SQL: List Days Past Due?

Posted on 2014-04-25
7
802 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 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
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 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 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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Migrating an SQL 2008 database to Oracle 12c 3 99
passing parameters to sql script oracle 4 40
Oracle 12c database link between pdb not working 20 72
use lov values 2 49
Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to recover a database from a user managed backup

786 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