On SQL Server 2022 (or Azure SQL DB/MI), you can use GENERATE_SERIES
:
DECLARE @start datetime = '20200101',
@end datetime = '20260101';
-- INSERT dbo.table(column)
SELECT h = DATEADD(HOUR, value, @start)
FROM GENERATE_SERIES(0, DATEDIFF(HOUR, @start, @end)) AS x;
On SQL Server 2016 or better, you can use STRING_SPLIT(REPLICATE
:
DECLARE @start datetime = '20200101',
@end datetime = '20260101';
-- INSERT dbo.table(column)
SELECT h = DATEADD(HOUR, ROW_NUMBER() OVER (ORDER BY @@SPID)-1, @start)
FROM STRING_SPLIT
(REPLICATE(CONVERT(varchar(max), ','),
DATEDIFF(HOUR, @start, @end)), ',') AS x;
On even older versions, well, you probably shouldn't be using anything older than that. (Never a bad idea to specify/tag with the specific version when asking your question.)
Here's a db<>fiddle but with a shorter date range because it doesn't gracefully handle thousands of output rows.