• mailtoashokberwal (4/25/2016)


    Thanks 🙂

    I tried another approach with CTE and that works fine too.

    WITH cte(a)

    AS

    (

    SELECT 1

    UNION ALL

    SELECT a+1 FROM cte WHERE a<10000

    )

    SELECT * FROM cte OPTION(MAXRECURSION 10000)

    That's going to be much, much slower. Jeff Moden wrote a great article about this technique. http://www.sqlservercentral.com/articles/T-SQL/74118/[/url]

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001