Home » SQL & PL/SQL » SQL & PL/SQL » Quarter first and last month
Quarter first and last month [message #187281] Fri, 11 August 2006 11:53 Go to next message
uicmxz
Messages: 48
Registered: July 2006
Member
How can I find first and last month of quarter?
For example:
if quarter = 2 the SQL query will return April and June.

Thanks
Re: Quarter first and last month [message #187298 is a reply to message #187281] Fri, 11 August 2006 14:07 Go to previous messageGo to next message
Littlefoot
Messages: 20901
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
This is quite obvious, as quarters and monts are strictly defined. I don't know whether such a solution suits your needs, or do you need something more sophisticated.
SELECT 
CASE
  WHEN &quarter = 1 THEN 'Jan, Mar'
  WHEN &quarter = 2 THEN 'Apr, Jun'
  WHEN &quarter = 3 THEN 'Jul, Sep'
  WHEN &quarter = 4 THEN 'Oct, Dec'
  ELSE 'Wrong quarter'
END q_mon
FROM dual;
Re: Quarter first and last month [message #187302 is a reply to message #187281] Fri, 11 August 2006 14:17 Go to previous messageGo to next message
Bill B
Messages: 1484
Registered: December 2004
Senior Member

select to_char(trunc(sysdate,'Q'),'Mon') start_month,
to_char(trunc(add_months(sysdate,3),'Q')-1,'Mon') end_month
from dual;


STA END
--- ---
Jul Sep
Re: Quarter first and last month [message #187317 is a reply to message #187302] Fri, 11 August 2006 17:55 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Bill, I think the starting point here was a quarter, not a date.
Re: Quarter first and last month [message #187551 is a reply to message #187281] Mon, 14 August 2006 07:30 Go to previous message
Bill B
Messages: 1484
Registered: December 2004
Senior Member
Sorry, that will teach me to finish reading a request Embarassed
Previous Topic: select/describe not working on table present in all_tables from sqlplus
Next Topic: how to view the table is parent or child. and if it is child table.how to find its parent table
Goto Forum:
  


Current Time: Sat Dec 10 22:48:05 CST 2016

Total time taken to generate the page: 0.07934 seconds