Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 8th, 2013, 02:44 PM
d0ggy d0ggy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 d0ggy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 32 sec
Reputation Power: 0
Help needed: sort of an aging query...

I have this query...

We pay all vendors with Net 20, Net 25 and Net 30 terms in due date + 15 days. I'm trying to develop a query that will tell me who is due now, who will be due in the next 7, next 10, next 14 and next 21 days.

The query below returns not due, due, due +7, etc... but anything that is due is also showing up in the +7, +10, etc - because if it's due now, it will still be due in a week!

How can I suppress these values if they are already due?

(or, if they're due in +7 days, how can I suppress in +10, +14, etc?)


SELECT
pv.vendor_name "Vendor",
nps.invoice_number "Invoice",
nps.invoice_date "Invoice Date",
nps.due_date "Due Date",
inv.terms "Terms",
(TO_DATE (sysdate) - nps.invoice_date) "Days Entered",
(CASE
when to_date(nps.due_date) < to_date(sysdate)
then (to_date(sysdate) - to_date(nps.due_date))
else NULL
end) "Days Overdue",
nps.amount_remaining "Amount Remaining",
-- 0-15
(CASE
WHEN (TO_DATE (sysdate) - nps.invoice_date) < 45
THEN nps.amount_remaining
ELSE NULL
END
) "Not Due",
(CASE
WHEN (TO_DATE (sysdate) - nps.invoice_date) >= 45
THEN nps.amount_remaining
ELSE NULL
END
) "Due" ,
(CASE
WHEN (TO_DATE (sysdate+7) - nps.invoice_date) >= 45
THEN nps.amount_remaining
ELSE NULL
END
) "+7 Days" ,
(CASE
WHEN (TO_DATE (sysdate+10) - nps.invoice_date) >= 45
THEN nps.amount_remaining
ELSE NULL
END
) "+10 Days" ,
(CASE
WHEN (TO_DATE (sysdate+14) - nps.invoice_date) >= 45
THEN nps.amount_remaining
ELSE NULL
END
) "+14 Days" ,
(CASE
WHEN (TO_DATE (sysdate+21) - nps.invoice_date) >= 45
THEN nps.amount_remaining
ELSE NULL
END
) "+21 Days"
FROM
inv,
pv,
nps
WHERE
and nps.amount_remaining <> 0
and inv.terms in ('Net 20', 'Net 25', 'Net 30')


sample output:
00470871 12/27/2012 1/26/2013 Net 30 12 126.62 126.62
59355648 11/28/2012 12/28/2012 Net 30 41 11 538.75 538.75 538.75 538.75 538.75 538.75
75793062 12/4/2012 1/3/2013 Net 30 35 5 950 950 950 950 950
52835 12/13/2012 1/13/2013 Net 30 26 298.92 298.92 298.92
52814 12/4/2012 1/3/2013 Net 30 35 5 330 330 330 330 330


any sql gurus have ideas?

Reply With Quote
  #2  
Old January 8th, 2013, 10:55 PM
spacebar208's Avatar
spacebar208 spacebar208 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: spaceBAR Central
Posts: 191 spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 9 h 59 m 25 sec
Reputation Power: 41
You need to use ranges based on your due_date and sysdate, something like:
Code:
case 
  when trunc( nps.due_date ) >= trunc( SYSDATE )
  then current
end as current

case
  when trunc( nps.due_date >= trunc( sysdate - 14 ) and trunc( nps.due_date ) < trunc( sysdate )
  then 0 to 14
end as 0 to 14

case
  when trunc( nps.due_date >= trunc( sysdate - 28 ) and trunc( nps.due_date ) < trunc( sysdate - 14 )
  then 15 to 28
end as 15 to 28

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Help needed: sort of an aging query...

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap