13 September 2016

Generate row set recursively

Well, live and learn! I think it is great:

with 
T1 as
(
select 1 as Row
union all  
select Row + 1 
from T1
where Row < 10
)

select * from T1

 

Result:

Row
1
2
3
4
5
6
7
8
9
10
   Tips, MSSQL

© Danylo Korostil