cheryl9063
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
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)))
this gives you the next quarter date: SELECT DATEADD(Q, 1, GETDATE())
therefore, the answer is: select DATENAME(Q, DATEADD(Q, 1, GETDATE()))
therefore, the answer is: select DATENAME(Q, DATEADD(Q, 1, GETDATE()))
Same result as jason but more brief
select DatePart(Q, GETDATE()) % 4 + 1
select DatePart(Q, GETDATE()) % 4 + 1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!!
ASKER
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())