3 added 5 characters in body
source | link
SELECT m,d,
  CASE
    WHEN (m,d) BETWEEN (1,1)   AND (1,29)   THEN 'Quater1''Quarter1'
    WHEN (m,d) BETWEEN (1,30)  AND (4,30)   THEN 'Quater2''Quarter2'
    WHEN (m,d) BETWEEN (5,1)   AND (7,30)   THEN 'Quater3''Quarter3'
    WHEN (m,d) BETWEEN (7,31)  AND (10,29)  THEN 'Quater4''Quarter4'
    WHEN (m,d) BETWEEN (10,29) AND (12,31)  THEN 'Quater1''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);
SELECT m,d,
  CASE
    WHEN (m,d) BETWEEN (1,1)   AND (1,29)   THEN 'Quater1'
    WHEN (m,d) BETWEEN (1,30)  AND (4,30)   THEN 'Quater2'
    WHEN (m,d) BETWEEN (5,1)   AND (7,30)   THEN 'Quater3'
    WHEN (m,d) BETWEEN (7,31)  AND (10,29)  THEN 'Quater4'
    WHEN (m,d) BETWEEN (10,29) AND (12,31)  THEN 'Quater1'
  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);
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);
2 added 478 characters in body
source | link
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)
SELECT m,d, 'Quarter' || my_quarter(m,d)
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.

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)
1
source | link

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 'Quater1'
    WHEN (m,d) BETWEEN (1,30)  AND (4,30)   THEN 'Quater2'
    WHEN (m,d) BETWEEN (5,1)   AND (7,30)   THEN 'Quater3'
    WHEN (m,d) BETWEEN (7,31)  AND (10,29)  THEN 'Quater4'
    WHEN (m,d) BETWEEN (10,29) AND (12,31)  THEN 'Quater1'
  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)
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.

Microsoft's syntax is usually a little bit longer, and less polished.