Creation of a date table using MSSQL. This is in response to a challenge posed on twitter to create a date table with the following columns:
- date
- year
- day of year
- quarter
- quarter start date
- quarter end date
- month number
- month name
- month start date
- month end date
- week number (in year)
- weekday name
- weekday name short
- weekday number
- day (in month)
- week start date
- weekend date
- year-month
- year-quarter
- fiscal year
- fiscal quarter
- is_holiday
- is_weekend
The query was optimized to run at a click. This was done by creating the date table (with 23 columns) using the CREATE TABLE command. Then a truncate command was introduced to clear any existing table content before inserting new contents into the table using a set of query commands from a Common Table Expressions (CTE). The CTE contains a list of dates from 1/1/2023 to 31/12/2023.