Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 1st, 2003, 09:32 AM
narsibvl narsibvl is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 9 narsibvl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
SQL Query

here is my requirement

I have these fields in a table

Due_Date
Cheque_Date
Fiscal_Year_Period

Due_Date is the date when a payment is due
Cheque_Date is the date when the payment was actually made.
and Fiscal_Year_Period is the fiscal year for that record.

When a due_date is past the payment is considered past_due. If the payment is made say 31 days after due_date the payment had been past_due for 30 days.


I need a SQL that returns past due payments for each fiscal_year_period and broken down into four different buckets for each of those fiscal_year_period.

The first bucket is 0 - 30 days past due(Which means the payment had been past due for 30 days)(cheque_date - due_date)
The second bucket is 30 - 60 days past due(Which mean the payment had been past due for more than 30 days but less than 60 days)
The third bucket is 60 - 90 days
and finally greater than 365 days.

Now a payment could be past due when a cheque has not been made at all till today which mean the cheque_date would be blank and in this case the bucket it falls into would be determined by the comparison of today(Sysdate) to the due_date

TIA
Narsi

Reply With Quote
  #2  
Old July 1st, 2003, 10:40 AM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 692 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 21 h 22 m 10 sec
Reputation Power: 19
what database?

Reply With Quote
  #3  
Old July 1st, 2003, 10:46 AM
narsibvl narsibvl is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 9 narsibvl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by hedge
what database?


Oracle Database and what i forgot to mention is that i need this in a stored procedure.

Reply With Quote
  #4  
Old July 1st, 2003, 02:45 PM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Pembroke Pines, Florida, USA
Posts: 2,300 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 3 h 2 m 4 sec
Reputation Power: 43
Hi narsibvl,

The Devshed community enjoys helping one another, but there are a couple recommendations to get the best results:

1. Descriptive titles to your questions -- "SQL Query" is not very descriptive. 99% of the questions in the Database section involve SQL queries . Your question title could be something like: "Date calculations in Oracle stored procedure".

2. At least attempt to solve your problem in some way, before posting a question. The "geek" community is much more interested in helping people that way. If you have tried some queries to solve your problem already, please post those, and explain what error messages you get, or why the query doesn't give the results you want.

Best regards,

rycamor
__________________
The real n-tier system:

FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

Amazon wishlist -- rycamor (at) gmail.com

Reply With Quote
  #5  
Old July 1st, 2003, 02:51 PM
narsibvl narsibvl is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 9 narsibvl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Date calculations in Oracle stored procedure

Quote:
Originally posted by rycamor
Hi narsibvl,

The Devshed community enjoys helping one another, but there are a couple recommendations to get the best results:

1. Descriptive titles to your questions -- "SQL Query" is not very descriptive. 99% of the questions in the Database section involve SQL queries . Your question title could be something like: "Date calculations in Oracle stored procedure".

2. At least attempt to solve your problem in some way, before posting a question. The "geek" community is much more interested in helping people that way. If you have tried some queries to solve your problem already, please post those, and explain what error messages you get, or why the query doesn't give the results you want.

Best regards,

rycamor


Keeping in mind the moderators views i hereby change the subject to the above mentioned.

Also here is a query i have which returns the records and assigns different buckets to it but i need a count of the buckets not just the individual records.


select nvl(cheque_date,sysdate),due_date, fiscal_year_period,
(
case
when (nvl(cheque_date,sysdate) - due_date) <= 30 then 'Bucket_1'
when (nvl(cheque_date,sysdate) - due_date) > 30 and (cheque_date - due_date) <= 60 then 'Bucket_2'
when (nvl(cheque_date,sysdate) - due_date) > 60 and (cheque_date - due_date) <= 90 then 'Bucket_3'
else 'Bucket_4'
end
) Bucket
from GETS_GS_AR_AGING_DETAIL

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > SQL Query


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway