I need to fill a time table to use it for joining the data in reporting services. Generally I do this with this code:
TRUNCATE TABLE tqTimeTable
DECLARE @CNT int
DECLARE @DATE datetime
DECLARE @END int
SET @CNT = 1
SET @DATE = 25567 -- 01.01.1970
SET @END = 20000 -- + 20k days => years 2024
WHILE(@CNT < @END)
BEGIN
INSERT INTO tqTimeTable (Tag, Monat, Jahr)
VALUES (DATEADD(day,@CNT,@DATE), MONTH(DATEADD(day,@CNT,@DATE)), YEAR(DATEADD(day,@CNT,@DATE)))
SET @CNT = @CNT + 1
END;
But this takes a while (on my test system around 2 minutes) so I hope someone had the same issue and solved it better then me. As I fire this statement from a .NET connection I need a faster solution or if there isn't one to raise the timeout of my connection.