Re: SQL Range of numbers in steps

From: Jonathan Leffler <jleffler_at_earthlink.net>
Date: Sat, 31 Mar 2007 20:17:06 GMT
Message-ID: <6lzPh.133128$_73.117978_at_newsread2.news.pas.earthlink.net>


Larry D wrote:
> I need to run a report on numbers in a range of numbers.
> Each one increments 8 from the last.
>
> For example:
>
> 10000
> 10008
> 10016
> etc.
>
> There are thousands of these numbers and it would not
> be worth my time to enter each of these individually.
>
> How do I do a search in SQL with this?
>
> I have programmed with other computer languages, so
> I know about for, next, step. . .
>
> I am using Viewpoint SQL and Microsoft Windows 2000.

Can't you use:

WHERE number >= 10000 AND number <= 20000 AND MOD(number, 8) = 0?

10000 is your lower limit; 20000 is my hypothesized upper limit.

If your starting number is not itself a multiple of 8, then you have to use a more complex expression:

WHERE number >= 9999 AND number < 19999 AND MOD(number, 8) = MOD(9999, 8)

You might have to worry about the definition of MOD if the range of numbers includes negative and positive values.

-- 
Jonathan Leffler                   #include <disclaimer.h>
Email: jleffler_at_earthlink.net, jleffler_at_us.ibm.com
Guardian of DBD::Informix v2005.02 -- http://dbi.perl.org/
Received on Sat Mar 31 2007 - 22:17:06 CEST

Original text of this message