Solved

Access Query / Expression :total of multiple feilds

Posted on 2003-11-10
1
2,246 Views
Last Modified: 2008-02-01
This should be simple looking to sum up all of these route times but when i run the query the total feild is empty why and how do I fix it ????

here is the query>

SELECT route.RouteType, route.RouteName, route.UnitType, [route]![Shear]+[route]![Amada]+[route]![Brake]+[route]![Spot]+[route]![Router]+[route]![Buff]+[route]![Powder]+[route]![Weld]+[route]![Deburr]+[route]![ReShear]+[route]![Radius]+[route]![Insert]+[route]![Drill]+[route]![CutoffSaw]+[route]![Notcher]+[route]![StoneSaw]+[route]![Hinge Emboss] AS totaltime, route.Shear, route.Amada, route.Brake, route.Spot, route.Router, route.Buff, route.Powder, route.Weld, route.Deburr, route.ReShear, route.Radius, route.Insert, route.Drill, route.CutoffSaw, route.Notcher, route.StoneSaw, route.[Hinge Emboss], *
FROM route;
0
Comment
Question by:cmmonline
1 Comment
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 100 total points
ID: 9717367
if ANY of the fields that are prt of the total is a NULL, then the Sum will result in a NULL value.

This looks like a very bad design, having all of those fields in the same record.

but since that is what you have, then you MUST account for the possible NULL values, using the NZ function:

SELECT route.RouteType, route.RouteName, route.UnitType, NZ([route]![Shear],0)+nz([route]![Amada],0)+nz([route]![Brake],0)+nz([route]![Spot],0)+nz([route]![Router],0)+nz([route]![Buff],0)+nz([route]![Powder],0)+nz([route]![Weld],0)+nz([route]![Deburr],0)+nz([route]![ReShear],0)+nz([route]![Radius],0)+nz([route]![Insert],0)+nz([route]![Drill],0)+nz([route]![CutoffSaw],0)+nz([route]![Notcher],0)+nz([route]![StoneSaw],0)+nz([route]![Hinge Emboss],0) AS totaltime, route.Shear, route.Amada, route.Brake, route.Spot, route.Router, route.Buff, route.Powder, route.Weld, route.Deburr, route.ReShear, route.Radius, route.Insert, route.Drill, route.CutoffSaw, route.Notcher, route.StoneSaw, route.[Hinge Emboss], *
FROM route;

a MUCH better and safer design would be to have a separate RouteTimes Table, :

RouteTime
------------------
RouteType
RouteStep
RouteTime

the Route Steps could then be either Strings like "ReShear", "Radius","Insert" etc, or else, if theses steps might change in the future, the have another table (Steps), and use the Primary key from that Table in the RouteTime Table.


The NZ function returns the value of the Field if it is NOT Null, and the value of the second argument (0 in the above) is the field IS NULL.

AW
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question