Link to home
Start Free TrialLog in
Avatar of cheryl9063
cheryl9063Flag for United States of America

asked on

sql date quarter

See my code below.. It's producing a record for each month in the QTR.. I only want one record per QTR.. The results set is supposed to look like

Q1 2011
Q2 2011

NOT
Q1 2011
Q1 2011
Q1 2011

and so on
(SELECT 'Q' + DATENAME(Q, @DateListedMLS) + CAST ('  ' AS VARCHAR(1)) + CAST(DATEPART(YY, @DateListedMLS) AS VARCHAR(200)))

Open in new window

Avatar of cheryl9063
cheryl9063
Flag of United States of America image

ASKER

I found the issue.. But I still need to know this:

This gives me the current QTR.. Based on the current date I want the next QTR.. How can I use below to get the next QTR? For example.. The below gives me 1 and I want 2.. In reality I will have a variable with a sale date like 02/11/2010.. I want to use that variable but get the QTR after that… Not QTR1 but QTR2..

select DATENAME(Q, GETDATE())
this gives you the next quarter date:  SELECT DATEADD(Q, 1, GETDATE())
therefore, the answer is:  select DATENAME(Q, DATEADD(Q, 1, GETDATE()))
Avatar of cyberkiwi
Same result as jason but more brief

select DatePart(Q, GETDATE()) % 4 + 1
ASKER CERTIFIED SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!!