October 29, 2020 at 12:00 am
Comments posted to this topic are about the item Setting Rows to Odd and Even Values
October 29, 2020 at 2:14 pm
Just a quick note on odd/even numbers. The quickest way to find out if a number is odd or even is to use a modulo function. If you take a number, n, and mod by 2 it returns 0 if even and 1 if odd. For example:
SELECT 3 AS number, 3 % 2 AS IsOdd
UNION all
SELECT 15, 15 % 2
union all
SELECT 159670, 159670 % 2;
October 29, 2020 at 2:20 pm
Thanks for your comment. It is true that if you are just trying to determine if a number is odd or even use modulo function.
In my case, as you can see in my article, the issue isn't trying to figure out if something is odd or even, but to force 1,2,3,4,5 to be 1,3,5,7,9
Or to force 1,2,3,4,5 to be 2,4,6,8,10
So then when you sort those rows together the records are interleaved. There is no way to use modulo to do that.
Thanks,
Ben
October 29, 2020 at 6:23 pm
Nicely done, Ben. Awesome simplification of an "interleaving" method using some very straight-forward math.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 29, 2020 at 6:25 pm
Thanks Jeff.
Ben
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply