views:

41

answers:

1

Hi there

I have the following query and I need to put OPTION (MAXRECURSION 1000) on the CTE section cause that place is where is the problem is (UNION ALL). So I put next to that line and compiled and not working and try different place is not working either (Incorrect syntax near the keyword 'OPTION'.). My question where I should put this into OPTION (MAXRECURSION XXX) ?

with tab AS 
(
    select 1 as id, 100 as start, 200 as en
    union all
    select 2, 200, 500),
    cte AS
    (
        select id,start,en from tab
        union all
        select id,start+1 , en from cte where start+1<=en
    )

SELECT id,start from cte
order by id

Note: If you are taking out union all select 2, 200, 500 from that, it works nicely because it's only up to 100.

+1  A: 
with tab AS 
(
    select 1 as id, 100 as start, 200 as en
    union all
    select 2, 200, 500),
    cte AS
    (
        select id,start,en from tab
        union all
        select id,start+1 , en from cte where start+1<=en
    )

SELECT id,start from cte
order by id
OPTION (MAXRECURSION 1000)
bobs
@bobs: Didn't realise that I need to put under the last select statement. :) I was trying to put inside the CTE or TAB section. Thanks
dewacorp.alliances
Hope it works for you. Good luck.
bobs