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!

help!!!!! 1

Status
Not open for further replies.

chidi

Technical User
Mar 24, 2003
42
0
0
NG
I am trying to write a query that will return data on a quarterly basis.
example, select data from table
where data is between 1st quarter and 2nd quarter.
data could be queried for any month in any quarter.
our company's quarter starts in march.
first quarter is mar - may, second quarter is jun-aug,
third quarter is sept - nov, and third quarter is dec-feb.
can someone please help me out on this?
thanks in advance.
 
Example:
select * from sometable where somedate between
'2002-03-01' and '2002-05-31'

Example:

selet * from sometable where year(somedate)=2002 and
month(somedate) in(3,4,5)

Example:
selet * from sometable where year(somedate)=2002 and
month(somedate) =3



 
thanks for your response but i don't see any quarter date format.
that is where the real problem is.
i need to able to display data like:
1Q 2Q 3Q 4Q
mar apr may; jun jul aug sep oct nov dec jan feb.

This way, i could get data for any month and it would fall under a particular quarter.
I truly appreciate anybody's help.
 
I may be off-base, but it sounds to me like you want to produce a report with this information. In which case, you should probably use a report generator such as PowerBuilder or Crystal Reports (which I personally have worked with). These report generators allow you to create your queries and manipulate the data to generate formatted reports as you describe in your message.

Regards,

 
this will do what you want
it works i just did on one of my tables

select *, quarter =
CASE
WHEN month(dateinspec) = 1 then '1Q'
WHEN month(dateinspec) = 2 then '1Q'
WHEN month(dateinspec) = 3 then '1Q'
WHEN month(dateinspec) = 4 then '2Q'
WHEN month(dateinspec) = 5 then '2Q'
WHEN month(dateinspec) = 6 then '2Q'
WHEN month(dateinspec) = 7 then '3Q'
WHEN month(dateinspec) = 8 then '3Q'
WHEN month(dateinspec) = 9 then '3Q'
WHEN month(dateinspec) = 10 then '4Q'
WHEN month(dateinspec) = 11 then '4Q'
WHEN month(dateinspec) = 12 then '4Q'
end
from qclog
 
Perfect!
This is what I want!!
Thanks a ton jjgraf !!!
 
A shorter but a little cryptic code could also be


select *, quarter = convert(varchar,convert(int,(month(dateinspec)+2)/3))+'Q'
from qclog


RT

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top