• eshandeepak (6/1/2010)


    When I executed this statement

    SELECT * FROM [MyDB].[dbo].[fn_GetTimestampRange] (DateAdd(YY,-10,GETDATE()), GETDATE(), 1)

    it returned 8726399 records in 2.29 mins and then gave error as

    "The statement terminated. The maximum recursion 100 has been exhausted before statement completion."

    Any idea why this error cropped up?

    It does say in the article: "(Note that if you want to produce more than 100 distinct days in a single query, you'll need to append OPTION(MAXRECURSION numberOfDays) to your query, where numberOfDays is the number of days you wish to loop through. This can be hidden away in the stored procedures, and SQL Server allows you to specify a MAXRECURSION of 0, which does not limit the amount of days that can be processed."