tags:

views:

80

answers:

4

So I have a column with different numbers and wish to categorize them by range within 30 minute intervals. So 5 would be 0-30, 697 would be 690-720, and 169 would be 150-180. I was first thinking of doing a case statement, but it doesn't look like Access 2003 supports it. Is there perhaps some sort of algorithm that could determine the range? Preferably, this would be done within the query.

Thank you.

A: 

Use / (integer division) and * (multiplication). 5/30*30 = 0 697/30*30 = 690 169/30*30 = 150 ...

+2  A: 

Take the integer portion of (number / 30) using the Int function and multiply it by 30 to get your lower bound, then add 30 to that number to get your upper bound.

Examples

Int(5 / 30) = 0 * 30 = 0
Int(697 / 30) = 23 * 30 = 690
Dan Goldstein
A: 

Let x be your column with the values you want to catalogue, the in pseudo-SQL you have:

select ((x/30)*30) as minrange,
(((x/30)+1)*30) as maxrange
from yourtable

(you should take the integer part of the division).
Hope this helps.

friol
A: 

This is fairly straight forward. You can just use the following.

(number \ 30) * 30

This will give you the lower index of your range. It does have one problem, which is that 30, 720, 180 etc, will be returned as themselves. This means your ranges either need to be 0-29, 690-719, etc, or have your caller take this into account.

This assumes you are using VBA where the '\' operator returns only the quotient. See more on VB operators here

grieve