SQL Server : Print 1 – 100 using recursive CTE

The query below print numbers from 1 to 100 using recursive CTE.

with cte(N) as
(
select 1 as N
union all
select cte.N + 1
from cte
where cte.N <100
)
select * from cte

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s