11 Mayıs 2015 Pazartesi

sql server cte and recursion

;WITH Numbers AS

(

    SELECT n = 1

    UNION ALL

    SELECT n + 1

    FROM Numbers

    WHERE n+1 <= 10

)

SELECT n

FROM Numbers

OPTION (MAXRECURSION 1000)

 

;WITH dayseries AS

(

    SELECT dt = CAST('2015-03-01' as date)

    UNION ALL

    SELECT DATEADD(DAY,1,dt)

    FROM dayseries

    WHERE DATEADD(DAY,1,dt)<'2015-04-01'

)

 

SELECT

       dt

FROM dayseries

OPTION (MAXRECURSION 1000)

Hiç yorum yok:

Yorum Gönder