Technical Article

Generating number sequences

,

Two queries below show one of many ways how You can generate a sequence of numbers.

/************************************************************************
*
* Author Rafal Skotak
* Purpose Generate sequence of numbers
* Date 2008-01-14
*
************************************************************************/
select value from
(
select 
((digit1 * 10) + digit2) * 10 + digit3 as value 
from
(select 0 as digit1 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) as d1
cross join
(select 0 as digit2 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) as d2
cross join
(select 0 as digit3 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) as d3
) as rs
order by
value


select value from
(
select 
(((((((bit6 * 2) | bit5) * 2 | bit4) * 2) | bit3) * 2 | bit2) * 2 | bit1) * 2 | bit0 as value
from
(select 0 as bit0 union select 1) as bit0rs
cross join
(select 0 as bit1 union select 1) as bit1rs
cross join
(select 0 as bit2 union select 1) as bit2rs
cross join
(select 0 as bit3 union select 1) as bit3rs
cross join
(select 0 as bit4 union select 1) as bit4rs
cross join
(select 0 as bit5 union select 1) as bit5rs
cross join
(select 0 as bit6 union select 1) as bit6rs
) as rs
order by value

Rate

4 (2)

You rated this post out of 5. Change rating

Share

Share

Rate

4 (2)

You rated this post out of 5. Change rating