Skip to Main Content

Write Great SQL Office Hours

Free tips and training every month! Subscribe for reminders and more from Office Hours. FAQ

Header container

March 16, 2021

13:00 UTC   Start Times Around the World

Subscribe to be notified of changes to sessions and give us feedback!

Having trouble watching the video on this page? Open the video in your browser.

Description

Generating days between two dates
Listing all the dates in a time period is a common requirement. For example, to report the sales each day for a month, including the days with no orders!

This session covered how to write SQL to do this, make this a reusable function with SQL macros, and why you - probably - want to store the dates instead of generating them instead.

Highlights include:

- 02:25 - Generating N rows and using this to create dates
- 04:25 - Generating a row/day between the oldest and newest dates in a table
- 07:30 - How to get every Monday in 2021
- 15:50 - Generate a row per month
- 18:15 - Generate a row per year
- 19:30 - Get a row per month including month start/end dates
- 24:00 - Using SQL macros to make reusable date-generation functions
- 26:00 - Demo of techniques covered
- 41:00 - Getting working days between two dates
- 42:20 - Code grinders vs database programmers
- 43:10 - Storing days in a dates table
- 45:10 - Dates table demo
- 50:00 - Optimizer estimates for generating dates vs storing
- 53:40 - Comparing generating dates or storing

Your Experts

  • #SELECTION#
    Chris Saxon

    Chris Saxon   

    Chris Saxon is an Oracle Developer Advocate and quizmaster on Dev Gym. His job is to help you get the best out of the Oracle Database and have fun with SQL! He's also part of the answer team on Ask TOM and creates YouTube videos at The Magic of SQL channel.
    #MISC#
    #ACTIONS#