clear markdown compare help donate or buy diddy dollings comments/suggestions/bugs a leap of faith? bible365
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 648577 fiddles created (15301 in the last week).

declare @mydate datetime, @mymon int, @myday int, @myyr int, @startyr char(4), @endyr char(4) select @mydate = '01/23/2016' select @mymon = month(@mydate), @myday = day(@mydate), @myyr = year(@mydate) select @startyr = convert(char(4), case when @mymon = 10 and @myday >= 30 then @myyr when @mymon in (11,12) then @myyr else @myyr - 1 end), @endyr = convert(char(4), case when @mymon = 10 and @myday >= 30 then @myyr + 1 when @mymon in (11,12) then @myyr + 1 else @myyr end); with quarters as (select * from (values ('Quarter1', convert(datetime,'10/30/'+@startyr), convert(datetime,'01/29/'+@endyr) ), ('Quarter2', convert(datetime,'01/30/'+@endyr), convert(datetime,'04/30/'+@endyr) ), ('Quarter3', convert(datetime,'05/01/'+@endyr), convert(datetime,'07/30/'+@endyr) ), ('Quarter4', convert(datetime,'07/31/'+@endyr), convert(datetime,'10/29/'+@endyr) ) ) as q(qtr, qstart, qend) ) select q.qtr, q.qstart, q.qend from quarters q where @mydate between q.qstart and q.qend;
qtr qstart qend
Quarter1 30/10/2015 00:00:00 29/01/2016 00:00:00
 hidden batch(es)