I'm not sure why this question is poorly received, what you want is something like this.. Here I use PostgreSQL which is a free database with convenient row syntax.
SELECT m,d,
CASE
WHEN (m,d) BETWEEN (1,1) AND (1,29) THEN 'Quarter1'
WHEN (m,d) BETWEEN (1,30) AND (4,30) THEN 'Quarter2'
WHEN (m,d) BETWEEN (5,1) AND (7,30) THEN 'Quarter3'
WHEN (m,d) BETWEEN (7,31) AND (10,29) THEN 'Quarter4'
WHEN (m,d) BETWEEN (10,29) AND (12,31) THEN 'Quarter1'
END AS q
FROM generate_series(timestamp '1-1-2016', timestamp '1-1-2017', '1 day')
AS gs(dt)
CROSS JOIN LATERAL ( VALUES
( EXTRACT(month FROM gs.dt)::smallint, EXTRACT(day FROM gs.dt)::smallint )
)
AS t(m,d);
You can put that lengthy case statement in a SQL function to make things a bit nicer.
CREATE FUNCTION my_quarter( m smallint, d smallint )
RETURNS smallint
AS $$
SELECT CASE
WHEN (m,d) BETWEEN (1,1) AND (1,29) THEN 1::smallint
WHEN (m,d) BETWEEN (1,30) AND (4,30) THEN 2::smallint
WHEN (m,d) BETWEEN (5,1) AND (7,30) THEN 3::smallint
WHEN (m,d) BETWEEN (7,31) AND (10,29) THEN 4::smallint
WHEN (m,d) BETWEEN (10,29) AND (12,31) THEN 1::smallint
END;
$$ LANGUAGE 'sql'
IMMUTABLE;
Now it's simple..
SELECT m,d, 'Quarter' || my_quarter(m,d) AS q
FROM generate_series(timestamp '1-1-2016', timestamp '1-1-2017', '1 day')
AS gs(dt)
CROSS JOIN LATERAL ( VALUES
( EXTRACT(month FROM gs.dt)::smallint, EXTRACT(day FROM gs.dt)::smallint )
)
AS t(m,d);
All that stuff that may look a bit foreign, all it does is generates date-sequence (test data), and extract from that sequence the month and the day.
Output looks like this,
m | d | q
----+----+----------
1 | 6 | Quarter1
1 | 15 | Quarter1
1 | 25 | Quarter1
3 | 29 | Quarter2
4 | 12 | Quarter2
4 | 15 | Quarter2
5 | 22 | Quarter3
6 | 11 | Quarter3
6 | 18 | Quarter3
6 | 28 | Quarter3
7 | 3 | Quarter3
9 | 2 | Quarter4
9 | 22 | Quarter4
10 | 17 | Quarter4
10 | 25 | Quarter4
(15 rows)
Microsoft's syntax is usually a little bit longer, and less polished.
CASE
statements to return the start and end dates of your custom date ranges if the value falls between.DATEFROMPARTS
to make that super simple.Calendar
table to perform these lookups. The one I have is based upon this one by Aaron Bertrand. You can customize the table to contain the date formats you want to use and assign your own quarters to each date. A quick and simple lookup.