Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting yes/no totals to show without - and zero without #Error 1

Status
Not open for further replies.

netrusher

Technical User
Feb 13, 2005
952
0
0
US
Below is the SQL code I am using on a query. This query is
counting Safes, UnSafes, Totals and then giving the pct of
Safes. It kind of works. My issues are as follows:
Everthing that is being counted are yes/no Check Boxes so
the totals are showing up as -17 or -22 etc etc. I would
like for those to be without the -. Also if the Safe Total
is 0 and the Total is 0 I would like for the Pct Safe
answer to be 0 or Blank instead of #Error. Does anyone have
the work around for this? Thanks for all help.

Code:
SELECT 
     Sum(IIf([BodyPinchPointsSafe]=True,[BodyPinchPoints],0)) AS Safe, 
     Sum(IIf([BodyPinchPointsUnSafe]=True,[BodyPinchPoints],0)) AS Unsafe, 
     Sum(IIf([BodyPinchPoints]=True,[BodyPinchPoints],0)) AS Totals, 
              Sum(IIf([BodyPinchPointsSafe]=True,[BodyPinchPoints],0))/Sum(IIf([BodyPinchPoints]=True,[BodyPinchPoints],0)) AS [Pct Safe], ObserversSecondTbl.Categories, ObserversSecondTbl.Behaviors
FROM 
     ObserversSecondTbl
WHERE 
     (((ObserversSecondTbl.Date) Between [Forms]![LiftsQueriesReports]![StartDateTxt] And [Forms]![LiftsQueriesReports]![EndDateTxt]))
GROUP BY 
     ObserversSecondTbl.Categories, ObserversSecondTbl.Behaviors;
 
You may try this:
Code:
SELECT 
 Abs(Sum(IIf([BodyPinchPointsSafe]=True,[BodyPinchPoints],0))) AS Safe
,Abs(Sum(IIf([BodyPinchPointsUnSafe]=True,[BodyPinchPoints],0))) AS Unsafe
,Abs(Sum([BodyPinchPoints])) AS Totals
,IIf(Sum([BodyPinchPoints])=0,0,Sum(IIf([BodyPinchPointsSafe]=True,[BodyPinchPoints],0))/Sum([BodyPinchPoints])) AS [Pct Safe]
,Categories,Behaviors
FROM ObserversSecondTbl
WHERE [Date] Between [Forms]![LiftsQueriesReports]![StartDateTxt] And [Forms]![LiftsQueriesReports]![EndDateTxt]
GROUP BY Categories,Behaviors

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top