/* Generate sequence nos on the fly without using any tables
sql 2005 you can select from cte into #temp table and
use this result set
OR
you can use this with other tables in cross join or join .
100 is kept as the limit , since max recursion cannot exceed this value .
you can expand on this idea to generate higher value limit .
*/ -- upto 100 numbers
with cte (nos) as
( select 1 as nos union all select cte.nos + 1
from cte where nos < 100 )
select nos from cte order by nos -- upto 200 numbers
with cte (nos) as
( select 1 as nos union all select cte.nos + 1 from cte where nos < 100 )
select nos
from cte
union all
select nos + 100
from cte order by nos ;
-- upto 199 numbers -- alternative way
with cte (nos)
as
( select 1 as nos union all select cte.nos + 1
from cte where nos < 100
union all
select cte.nos + 100 from cte where nos < 100 )
select nos from cte order by nos ;
/* you can use select nos into #temp from cte to port into a temp table */
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment