Tuesday, May 10, 2016

The maximum recursion 100 has been exhausted before statement completion. in sqlserver

Error:-
WITH DateTable
AS
(
    SELECT CAST('2014-01-30 17:43:00.000' as Date) AS [DATE]
    UNION ALL
    SELECT DATEADD(dd, 1, [DATE]) FROM DateTable
    WHERE DATEADD(dd, 1, [DATE]) <= cast('2016-05-10 05:47:03.000' as Date)
)
SELECT  dt.[DATE] FROM [DateTable] dt

Msg 530, Level 16, State 1, Line 1
The statement terminated. The maximum recursion 100 has been exhausted before statement completion.

Solution:-
WITH DateTable
AS
(
    SELECT CAST('2014-01-30 17:43:00.000' as Date) AS [DATE]
    UNION ALL
    SELECT DATEADD(dd, 1, [DATE]) FROM DateTable
    WHERE DATEADD(dd, 1, [DATE]) <= cast('2016-05-10 05:47:03.000' as Date)
)
SELECT  dt.[DATE] FROM [DateTable] dt
option (maxrecursion 0);

4 comments:

  1. Nice blog, keep writing like this

    Find here online price details of companies selling Mattress Cover Waterproof. Get info of suppliers, manufacturers, exporters, traders of Mattress Cover Near Me for buying in India.

    ReplyDelete
  2. Nice blog, keep writing like this

    Buy Milwaukee at low prices in UK. Select from range of home improvement tools & Milwaukee UK of all brands from tools4trade.co.uk

    Milwaukee
    Milwaukee UK
    Milwaukee Power Tools
    Milwaukee Fuel
    Milwaukee UK Cordless
    Corded Power Tools
    Milwaukee power tools UK

    ReplyDelete