Consider returning a series of numbers 1-31.
Here's the code:
WITH Number_Sequence AS ( SELECT 1 AS sequence UNION ALL SELECT sequence+1 FROM Number_Sequence W WHERE sequence < 31 ) SELECT * FROM Number_Sequence
Now that it's a result set, it may be used to join to another table. Since this is a CTE and not a physical table, it's not indexed and could degrade processing. Table size should always be considered before joining this CTE to another table.
Here's another sample code that simulate bit positions in a byte:
with GroupNumbers as ( select 1 as byte, 1 as from_bit, 8 as to_bit union all select byte + 1, from_bit + 8, to_bit + 7 from GroupNumbers where to_bit < 64 ) select * from GroupNumbers
As always, comments are welcome...
~~CK
No comments:
Post a Comment