customized quarter calculation in sql

Hi Team, We have got a customized quarter list from client which we need to take reference to get data in SQL. Could you please help.

 30-Oct    29-Jan AS Quarter1
 30-Jan    30-Apr AS Quarter2
 01-May    30-Jul AS Quarter3
 31-Jul    29-Oct AS Quarter4

If today falls beween any of the quarter we need start date in date format

for example if today is Jan/02/2018 then it shall return start date as '30-10-2017 00:00:00' and end date as '29-01-2018 00:00:00'

if today is Dec/30/2017 then it shall return start date as '30-10-2017 00:00:00' and end date as '29-01-2018 00:00:00'

more ▼

asked Oct 06, 2017 at 04:24 PM in Default

avatar image

1 2

@aman6496 It is not clear what you actually need to happen. Do you need a function which returns the custom quarter range? Or is it something else? In any case it would make sense to create a table with 4 rows per each year period. Populate it with data for several years before and after this year, depending on your data requirements. This way you can always join to this table on the BETWEEN basis and figure out to which quarter any given date belongs.Please note that the ranges they gave you do not have the same number of days, i.e. first quarter has 92 while all others - 91. This means that their calendar is just a custom fiscal calendar which kinda mimics the standard calendar but begins on 30th of October. In other words, it is a calendar with full months, no full weeks.

Oct 06, 2017 at 07:04 PM Oleg
(comments are locked)
10|1200 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Oct 06, 2017 at 04:24 PM

Seen: 51 times

Last Updated: Oct 09, 2017 at 09:27 AM

Copyright 2018 Redgate Software. Privacy Policy