Skip to content

Instantly share code, notes, and snippets.

@GabrielMMelo
Created July 28, 2020 11:22
Show Gist options
  • Save GabrielMMelo/4e0bae6d909288b0d945d7e0aa481f4a to your computer and use it in GitHub Desktop.
Save GabrielMMelo/4e0bae6d909288b0d945d7e0aa481f4a to your computer and use it in GitHub Desktop.
Select that returns all dates between 2 dates
-- FROM here: https://stackoverflow.com/questions/7824831/generate-dates-between-date-ranges
DECLARE @StartDate DATE = '20110901'
, @EndDate DATE = '20111001'
SELECT DATEADD(DAY, nbr - 1, @StartDate)
FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY c.object_id ) AS Nbr
FROM sys.columns c
) nbrs
WHERE nbr - 1 <= DATEDIFF(DAY, @StartDate, @EndDate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment