Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating and Using Calendar Tables

Similar presentations


Presentation on theme: "Creating and Using Calendar Tables"— Presentation transcript:

1 Creating and Using Calendar Tables
Edward Pollack Creating and Using Calendar Tables

2 Agenda Making Date Calculations Fast and Efficient
What is a calendar table? Simplifying code. Improving maintainability. Performance optimization. Demos Questions?

3 What is a Calendar Table?
Table of dates and date components. Can contain large numbers of metrics. Eliminates date math on-the-fly. Eliminates ad-hoc date-math columns in tables. Used in: Analytics Reporting Anywhere you are sick of…

4 …this…

5 Calendar Tables: A Quick Glance
Demo Calendar Tables: A Quick Glance

6 What Can go in a Calendar Table?
Any date-based metric you can dream of. Date parts. Relative location in the calendar. String representations. Components of week, month, quarter, year, etc… Weekdays, business days, holidays, holiday seasons. Alternate calendars, such as fiscal, 4-5-4, etc…

7 Creating a Calendar Table
Demo Creating a Calendar Table

8 Simplifying Code Remove frequent date math from any part of a query.
Make TSQL more readable. Reduce mistakes and improve quality.

9 Demo Simplifying Code

10 Simplifying Code (cont.)
Store very complex calculations for future use. Can include date-based business logic Easter, lunar holidays, alternate calendars, etc… Putting this code into TSQL is messy and error-prone.

11 Demo Determining Easter

12 Improving Maintainability
Date definitions can be maintained in one place. Reduces repeated code. Creates authoritative source for date-based metrics. No need to reinvent the wheel. Reduce mistakes, increase reliability of code.

13 Performance Optimization
Calendar table rarely/never changes. Calendar table can be heavily indexed. Remove messy functions and date math from filters, aggregates, and ordering. Focuses seeks/scans on the calendar table. Removes complexity from queries on large tables.

14 Demo More Demos!

15 Conclusion Calendar tables can: …and they are extremely inexpensive!
Simplify code and make it more readable. Improve performance. Improve maintainability. Standardize date-based business logic. Help generate date ranges for processing. Provide a calendar data source in reporting. …and they are extremely inexpensive!

16 Questions???

17 Contact Info & Links Ed Pollack @EdwardPollack SQL Shack SQL Server Central SQL Saturday Albany (2019) Thank you!!!


Download ppt "Creating and Using Calendar Tables"

Similar presentations


Ads by Google