Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quarter Date Format -Urgent

Status
Not open for further replies.

chidi

Technical User
Mar 24, 2003
42
0
0
NG
It seems like I send a faq everyday but do not see appear on the forum.
Let me try again.
I need to know if someone can tell me how to write a quarter function.
Example, I have 2 tables, t1 and t2.
t1 has 3 columns - month_no as char, year_no as char
and a key called calendar_id.
t2 has two colums - amount and key calendar_id.
What I am trying to do is to determine the quarterly amount for each year.
I need my output to look like this:
period amount
1q98 200
2q98 300
3q98 0
4q01 50.
Like I said, it could be any year and any quarter.
I just the amount displayed for each quarter of a given year.
Can anyone please help me?
chidi
 
Try something like this (use your date separator):

select
quarter(date('01/'||month_no||'/'||year_no)),
year_no,
sum(amount)
from
t1 a,
t2 b
where
a.calendar_id = b.calendar_id
group by
quarter(date('01/'||month_no||'/'||year_no)),
year_no

HTH,
Alphonsus.
 
Thank you very much for responding.
What I really wanted is a code that would return quarter as
1q97, 2q98, or 4q99 or any given quarter for any given year.
At any given instance, I would like the code to return any
quarter that applies.
What you did for me could not accomplish that.
chidi
 
That's an unusual format, but you can get it if you concatenate

Try...

SELECT
TRIM(CHAR(QUARTER(MyTable.MyDate))) || 'q' || SUBSTR(CHAR(YEAR(MyTable.MyDate)),2,2)
FROM
MyTable

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top