Created
July 28, 2020 11:22
-
-
Save GabrielMMelo/4e0bae6d909288b0d945d7e0aa481f4a to your computer and use it in GitHub Desktop.
Select that returns all dates between 2 dates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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