开发者

How to yield recursion in query? What is the use of "With" ? How it works internaly?

开发者 https://www.devze.com 2023-01-19 17:41 出处:网络
Why this que开发者_如何学JAVAry is completed with error ? ;with tempData as ( select 32 as col1, char(32) as col2

Why this que开发者_如何学JAVAry is completed with error ?

;with tempData as
 (
        select 32 as col1, char(32) as col2
        union all
        select col1+1, char(col1+1) from tempData
 )
select * from tempData


Recursion needs a terminating condition. For example

;with tempData as ( 
select 32 as col1, char(32) as col2 
union all 
select col1+1, char(col1+1) from tempData 
where col1 < 255
) 
select * from tempData
option (maxrecursion 223)

With regards to the question in the title about how it works internally see this answer.


You have an infinite loop: where should it end?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号