Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kenny-evitt/5853174 to your computer and use it in GitHub Desktop.
Save kenny-evitt/5853174 to your computer and use it in GitHub Desktop.
Generate a temporary table of dates from a 'numbers' table. The minimum 'Number' value in the table dbo.Numbers is 1. The "DATEDIFF(...)" expression removes the time portion of the "GETDATE()" function value.
SELECT NumberedDate = DATEADD( day, DATEDIFF(day, 0, GETDATE()) - Number + 1, 0 )
INTO #lastSixtyDays
FROM dbo.Numbers
WHERE Number < 62;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment