473,386 Members | 1,621 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,386 software developers and data experts.

Query returning "error#" instead of zero

I have a query that subtracts this months mileage from last months, then
divides that mileage value by the fuel used by the vehicle to figure this
months miles per gallon.
Whenever one of the values is 0, it returns "error#".
Do I use Nz function to fix this?
Here is the query

SELECT [Monthly mileage log 2004].AssetID, [JanMiles]-[Monthly mileage log
2004]![YearBeginingMileage] AS JanMilesDriven, [JanMilesDriven]/[Monthly
mileage log 2004]![JanFuel] AS JanMpg, [Monthly mileage log
2004]![FebMiles]-[Monthly mileage log 2004]![JanMiles] AS FebMilesDriven,
[FebMilesDriven]/[Monthly mileage log 2004]![FebFuel] AS FebMpg, [Monthly
mileage log 2004]![MarMiles]-[Monthly mileage log 2004]![FebMiles] AS
MarMilesDriven, [MarMilesDriven]/[MarFuel] AS MarMpg, [AprMiles]-[MarMiles]
AS AprMilesDriven, [AprMilesDriven]/[AprFuel] AS AprMpg, [Monthly mileage
log 2004]![MayMiles]-[Monthly mileage log 2004]![AprMiles] AS
MayMilesDriven, [MayMilesDriven]/[Monthly mileage log 2004]![MayFuel] AS
MayMpg, [Monthly mileage log 2004]![JunMiles]-[Monthly mileage log
2004]![MayMiles] AS JunMilesDriven, [JunMilesDriven]/[Monthly mileage log
2004]![JunFuel] AS JunMpg, [Monthly mileage log 2004]![JulMiles]-[Monthly
mileage log 2004]![JunMiles] AS JulMilesDriven, [JulMilesDriven]/[Monthly
mileage log 2004]![JulFuel] AS JulMpg, [Monthly mileage log
2004]![AugMiles]-[Monthly mileage log 2004]![JulMiles] AS AugMilesDriven,
[AugMilesDriven]/[Monthly mileage log 2004]![AugFuel] AS AugMpg, [Monthly
mileage log 2004]![SepMiles]-[Monthly mileage log 2004]![AugMiles] AS
SepMilesDriven, [SepMilesDriven]/[Monthly mileage log 2004]![SepFuel] AS
SepMpg, [Monthly mileage log 2004]![OctMiles]-[Monthly mileage log
2004]![SepMiles] AS OctMilesDriven, [OctMilesDriven]/[Monthly mileage log
2004]![OctFuel] AS OctMpg, [Monthly mileage log 2004]![NovMiles]-[Monthly
mileage log 2004]![OctMiles] AS NovMilesDriven, [NovMilesDriven]/[Monthly
mileage log 2004]![NovFuel] AS NovMpg, [Monthly mileage log
2004]![DecMiles]-[Monthly mileage log 2004]![NovMiles] AS DecMilesDriven,
[DecMilesDriven]/[Monthly mileage log 2004]![DecFuel] AS DecMpg,
([JanMpg]+[FebMpg]+[MarMpg]+[AprMpg]+[MayMpg]+[JunMpg]+[JulMpg]+[AugMpg]+[Se
pMpg]+[OctMpg]+[NovMpg]+[DecMpg])/12 AS MpgYearAvg
FROM [Monthly mileage log 2004];
Nov 13 '05 #1
2 2067
noname wrote:
I have a query that subtracts this months mileage from last months, then
divides that mileage value by the fuel used by the vehicle to figure this
months miles per gallon.
Whenever one of the values is 0, it returns "error#".


Well, do you have any zero values in the denominators, such as the fuel
values?

Your structure is very, very poor, you might as well just be using a
spreadsheet. Much better to have one table (it looks as if you have a
tble per year - bad, bad design), and not worry about months:

TBL_VEHICLE_LOG (or something)

VL_PK autonumber
VL_TRANS_DATE date 'transaction date
VL_MILES numeric 'make sure default value is 0
VL_FUEL numeric 'make sure default value is 0

You can then easily get monthly, yearly figures using month(), year()
and if you have a fiscal year system that is other than 1 Jan you can
write functions to get what you want.

Sorry if I sound like I'm being mean, but if someone came to me with a
data structure like that (and I run maintenance systems for vehicles) I
would throw him/her out of my office angrily.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #2
Tim Marshall wrote:
TBL_VEHICLE_LOG (or something)

VL_PK autonumber
VL_TRANS_DATE date 'transaction date
VL_MILES numeric 'make sure default value is 0
VL_FUEL numeric 'make sure default value is 0


And of course, you'd want a link to a SEPARATE vehicle table.

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kevin | last post by:
Help, I am running a pass through query to oracle from SQL server 2000 as follows; select * from openquery(nbsp, 'select * from FND_FLEX_VALUES') I have run this query through both DTS and...
2
by: deko | last post by:
SELECT Nz(Min(),#1/1/1000#) AS NextAppt, Appt_ID FROM tblAppointments WHERE Entity_ID=!! AND ApptDate>=Date() If I do not include Appt_ID, it works fine. But I need the ID so I can join other...
2
by: Jean | last post by:
Hello everyone, I was having the following problem with a query, and after failing to find a similar solution on these newsgroups I decided to post here. I am quite new to Access, so would...
5
by: Peter Steele | last post by:
We have an application that when it runs in the IDE in debug mode an unhandled exception is occurring in a system header file associated with STL stirngs. The actual statement that crashes is ...
0
by: | last post by:
Hello NG! I try to call a WebService from a mobile device. The WebService should return a DataSet, so the call looks like mDataSet = mWebSrv.GetDataSet(<Params>) but instead of returning a...
2
by: matt | last post by:
hello, i have an .RPT file that i am using to load a report via the ASP.NET CrystalReportViewer control. i dont include my .RPTs as embedded resources...instead i load the absolute path of the...
6
by: Don Lancaster | last post by:
I need to progrmatically do this inside a loop this.fh03.value = fixFloat (Harms, numPoints) ; with the numbers changing per an index. If I try curHvals = "03" ; // (derived from...
4
by: dstorms | last post by:
Hi, I'm trying to create a form with a list box with 2 columns and a button that opens the selected record in the appropriate form. In the sample below, the first column lists the type of equipment...
1
cori25
by: cori25 | last post by:
Paycode': IIf(="01","Meeting",IIf(="02","Training",IIf(="04","Special Project",IIf(="05","QC",IIf(="06","MDU",IIf(="07","UG",IIf(="08","2nd Man",IIf(="09","Sr Tech Other",IIf(="10-1","Loan Out to...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.