473,405 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Round to nearest 200 in a query

I'm designing a database which takes into consideration the total square footage of a house and multiplies it by a predetermined multiplier to determine the cost. However, the table with the predetermined multipliers is designed for every 200 sq. ft.

IE:
Total Sq. foot - - - - Multiplier
400 - - - - - - - - - - - 1.032
600 - - - - - - - - - - - 1.025
800 - - - - - - - - - - - 1.013
1000 - - - - - - - - - - - 1.000
1200 - - - - - - - - - - - 0.992
etc, etc to 6000 sq. ft

I have another query which takes into consideration the info provided by the user and returns a sq. footage. but this number may be 1120.

What I'm trying to do is take this "1120" and round it up to 1200, so a value for the multiplier would correspond.

So far this is the best function I've been able to get return some value, however it's retuning really strange numbers like and every time I go from design mode to datasheet view, I get a different result.


Expand|Select|Wrap|Line Numbers
  1. SELECT [que:Main].Shape, [que:Main].[Total Sq Footage], Rnd([que:Main]![Total Sq Footage]) AS [Sq Foot]
Feb 23 '08 #1
9 1930
Scott Price
1,384 Expert 1GB
You're going to need a coded function something like the following in order to accomplish this. Being a public function you can use it inside a query... This is quick and dirty...

Paste this into a standard code module, if you need instructions how to do so, let me know.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Public Function Round200(ByVal sqft As Integer) As Integer
  4.  
  5. Dim squareFootage As Integer
  6.  
  7. squareFootage = 0
  8.  
  9. Select Case sqft
  10.     Case Is <= 400
  11.         squareFootage = 400
  12.     Case 401 To 600
  13.         squareFootage = 600
  14.     Case 601 To 800
  15.         squareFootage = 800
  16.     Case 801 To 1000
  17.         squareFootage = 1000
  18.     Case 1001 To 1200
  19.         squareFootage = 1200
  20.     'etc etc etc
  21. End Select
  22.  
  23. Round200 = squareFootage
  24.  
  25. End Function
The sql to call this function will look like this:
Expand|Select|Wrap|Line Numbers
  1. Select Round200([SQFTFieldName]) As SqFootage

Regards,
Scott
Feb 23 '08 #2
Thanks for the quick response. I’m fairly new to Access and have never used modules before, but I have a fair idea of what you’re trying to explain.

So what I did is copied your coding into a module and called it Round200.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Function Round200(ByVal sqft As Integer) As Integer
  5.  
  6. Dim squareFootage As Integer
  7.  
  8. squareFootage = 0
  9.  
  10. Select Case sqft
  11.     Case Is <= 400
  12.         squareFootage = 400
  13.     Case 401 To 600
  14.         squareFootage = 600
  15.     Case 601 To 800
  16.         squareFootage = 800
  17.     Case 801 To 1000
  18.         squareFootage = 1000
  19.     Case 1001 To 1200
  20.         squareFootage = 1200
  21.     'etc etc etc
  22. End Select
  23.  
  24. Round200 = squareFootage
  25.  
  26. End Function
  27.  

Then went back to query , into SQL view and copied your example but changed it so the ([SQFTFieldName]) was where the module gets the info from and it looks like this:

Expand|Select|Wrap|Line Numbers
  1. Select Round200([que:Main].[Total Sq Footage]) As SqFootage 
But when I go to view I get:

Expand|Select|Wrap|Line Numbers
  1. The SELECT statement includes a reserved word or argument name that is misspelled or missing, or the punctuation is incorrect.
  2.  
OR

Do I somehow integrate the coding you’ve provided into the query I have already y started
Expand|Select|Wrap|Line Numbers
  1. SELECT [que:Main].Shape, [que:Main].[Total Sq Footage], [que:Main]![Total Sq Footage] AS [Sq Foot]
  2. FROM [que:Main], [tbl:ShapeMultiplier]
  3. GROUP BY [que:Main].Shape, [que:Main].[Total Sq Footage];
  4.  
Thanks in advance for any assistance you can provide.
Bruce
Feb 23 '08 #3
missinglinq
3,532 Expert 2GB
Or maybe a simpler formula (as much as I dislike iif())

SqFt = iif (SqFt Mod 200 <> 0, SqFt + 200 - (SqFt Mod 200), SqFt)

Linq ;0)>
Feb 23 '08 #4
ADezii
8,834 Expert 8TB
I'm designing a database which takes into consideration the total square footage of a house and multiplies it by a predetermined multiplier to determine the cost. However, the table with the predetermined multipliers is designed for every 200 sq. ft.

IE:
Total Sq. foot - - - - Multiplier
400 - - - - - - - - - - - 1.032
600 - - - - - - - - - - - 1.025
800 - - - - - - - - - - - 1.013
1000 - - - - - - - - - - - 1.000
1200 - - - - - - - - - - - 0.992
etc, etc to 6000 sq. ft

I have another query which takes into consideration the info provided by the user and returns a sq. footage. but this number may be 1120.

What I'm trying to do is take this "1120" and round it up to 1200, so a value for the multiplier would correspond.

So far this is the best function I've been able to get return some value, however it's retuning really strange numbers like and every time I go from design mode to datasheet view, I get a different result.


Expand|Select|Wrap|Line Numbers
  1. SELECT [que:Main].Shape, [que:Main].[Total Sq Footage], Rnd([que:Main]![Total Sq Footage]) AS [Sq Foot]
Expand|Select|Wrap|Line Numbers
  1. IIf(Total_Square_Footage < 400, 400, IIf(Total_Square_Footage Mod 200 = 0, Total_Square_Footage, (Fix(Total_Square_Footage / 200) * 200) + 200))
  2.  
Feb 23 '08 #5
Thanks everyone for your suggestios, it returns exactly what I was hoping for

Bruce
Feb 23 '08 #6
Scott Price
1,384 Expert 1GB
Just as a curiosity I plugged this in and this is working just fine for me in my test database:
Expand|Select|Wrap|Line Numbers
  1. SELECT Round200( PRODUCT.blahblablah) As Rounded
  2. FROM PRODUCT;
Rather strange that it's not working for you! What version of Access are you using?

Really this is kind of beside the point since you have a workable solution, it's just kind of strange :-)

Regards,
Scott
Feb 23 '08 #7
Right now we're still using Access 97 at work and I know some suggestions only work with 2003 and newer. But I will try your suggestion again, just to see what happens.

Once again thanks for your help.
Feb 23 '08 #8
Scott Price
1,384 Expert 1GB
That's probably the reason. I'm not sure on the A97 versus A2003 specifics of this code, but I'll assume that's the issue! Good to have that solved at least :-)

Regards,
Scott
Feb 23 '08 #9
missinglinq
3,532 Expert 2GB
The solutions here involving the iif() function won't work in ACC97, of course. It didn't arrive until 2000. You could write a custom function using the If...End If construct to do the same thing and then call that fumction from the query.

Linq ;0)>
Feb 23 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: tertius | last post by:
Hi, I'm trying to round my float total to the nearest .05 cents. 12.01 should produce 12.00 0.14 should produce 0.10 2.28 " 2.25 703.81 " 703.80 ...
6
by: Penguin | last post by:
At some long ago time Steve Jorgensen answered thus: Subject: Re: How can I round a time? Newsgroups: comp.databases.ms-access Date: 1998/12/11 Access represents a date internally as a double...
9
by: Ronald W. Roberts | last post by:
I'm having a problem understanding the Round function. Below are quotes from two books on VB.NET. The first book shows examples with one argument and how it rounds. The second book something...
0
by: thaisummitneel | last post by:
sir I have created a database in ms-access.Connected database using ADODB I have written a query to round integer to nearest value such as con.execute"update tablename set...
4
by: naren2345 | last post by:
Would this expression round an integer n to the nearest power of 4 ? ((n-1)|3) + 1
10
by: Henrootje | last post by:
I am looking for a way to round down the results of a calculation in a query f.e.: in a query this calculation is performed: a/b = c 5/3 = 1,666666667
4
by: Jassim Rahma | last post by:
I have a number, for example 0.152 or 1.729 and I want to allow to round to the first 0.010 or 0.050 or 0.100
6
by: dkirkdrei | last post by:
I am looking for a way to round a number (which will be displayed as a dollar amount) to the nearest nickel. Using the php round function only allows you to control the number of decimal places in...
0
by: Edwin.Madari | last post by:
>>round(76.1, -2) 100.0 80.0 76.0 builtin function round, will work for you...... Help on built-in function round in module __builtin__: round(...) round(number) -floating point number
3
by: Arie | last post by:
Hello, I have a table with marks (from Exams) and when I create a query a calculated field with an expression like: Round(+ )/2 I am confronted with the problem that Access has a strange...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.