Topic: SQL*Plus and PL/SQL >> QUERY TO EXTRACT DATE IN A RANGE
|
Disclaimer: The purpose of all dbapool forums including OCP and Other Oracle Certification forums is to help each other with specific issues but not to share dump and copyrighted exam content, materials or intellectual property.
You may review the entire Oracle Certification Program Candidate Agreement online Here.
|
|
|
|
| Title: QUERY TO EXTRACT DATE IN A RANGE |
| Randy |
Posted: Jun 11, 2007 11:54:40 AM |
Total Post: 4
Joined: May, 2007
|
Hello Everyone,
I need some advise on the following query:
select decode( Th.Reference_from_account_id,
'9999999999999999', Th.Transaction_amount * -1,
Th.Transaction_amount
) as Amount,
Th.Post_date, Th.Transaction_class, Th.Transaction_type,
Tt.Transaction_class_desc, Tt.Transaction_type_desc,
decode( Th.Reference_from_account_id,
'9999999999999999', Th.From_account_balance,
Th.To_account_balance
) as Balance,
Th.Transaction_date, Th.Reference_to_memo
from Trans_hist Th, Trans_type Tt
where ( '9999999999999999' in
( Th.Reference_from_account_id, Th.Reference_to_account_id )
)
and Th.Transaction_class != 'W'
and ( ( Th.Transaction_class != 'D'
and Th.Transaction_type != 'T'
and trunc(Th.Post_date) = to_date('05-JUN-07','DD-MON-YY')
) --lower range
or ( Th.Transaction_class = 'D'
and Th.Transaction_type = 'T'
and trunc(Th.Post_date) = to_date('06-JUN-07','DD-MON-YY')
) --upper range
)
and Th.Transaction_type = Tt.Transaction_type
and Th.Transaction_class = Tt.Transaction_class
order by Post_date desc
The above query works for that range. However, if I try to change the date param to say:
lower range (01-jun-07)
upper range(04-jun-07)
I don't get the desired result. The idea is to produce data on business days only such such:
1. Between June 1 and June 4
2. Between June 4 and June 5
3. Between June 5 and June 6
4. Between June 6 and June 7 and so on.
I've tried several permutations but I could not get the desired result. The post_date field contains date and time.
Thank you for your help.
Sincerely,
Randy |
|
|
| Time Zone: EDT |
Send this thread to your friend |
|
|
|
|
Forum Rules & Description
Who Can Read The Forum? Any registered user or guest
Who Can Post New Topics? Any registered user
Who Can Post Replies? Any registered user
|
| |
Get FREE Magazines
|
Top 10 Forum User
|
| Murtuja Khokhar | 857 |
| Mohammed Taj | 746 |
| positive fanatic | 483 |
| Jayanta Sur | 479 |
| Vigyan Kaushik | 386 |
| Gopu Gopi | 335 |
| Gitesh Trivedi | 322 |
| Vinoth Kumar | 264 |
| neeraj sharma | 258 |
| Ramesh Jois | 246 |
|
|