Calculating financial week in SQL

sabb 1 Reputation point
2022-01-17T02:41:27.03+00:00

Hi,
I need your help in calculating financial weeks based on below rules:

  1. if there are 3 or more working days (Monday to Friday) in the last week of June then it is week 53
  2. if there less than 3 working days in the last week of June then it is week 1 in the next financial year.
    3.My calendar starts from year 2012.

I appreciate your help.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,815 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,559 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tom Phillips 17,716 Reputation points
    2022-01-17T13:13:08.293+00:00

    Create a "calendar table" and calculate this once. Then you can use it for your query.

    See:
    https://weblogs.sqlteam.com/dang/2010/07/19/calendar-table-and-datetime-functions/