Chat with a LIVE Microsoft Access Expert!
 
       
 

         

   

Go Back   Access World Forums > Microsoft Access Discussion > Queries

 
 
Chat with a LIVE Microsoft Access Expert!
Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-08-2007, 02:51 AM
Oscar_W Oscar_W is offline
Registered User
 
Join Date: Mar 2006
Location: Portsmouth
Posts: 42
Oscar_W is on a distinguished road
Query calculations

Thanks mainly to John K I have the following code from a previous post which identifies when a 'Unit' has been entered at 2 different 'JettyNumber' on the same 'StartDate'

Code:
SELECT Qry_All_Ops.StartDate, Qry_All_Ops.Unit, Count(Qry_All_Ops.Unit) AS CountOfUnit, Sum(Qry_All_Ops.JettyNumber) AS SumOfJettyNumber, [SumOfJettyNumber]/[CountOfUnit] AS Result, [result]=CInt([result]) AS Expr1
FROM Qry_All_Ops
WHERE (((Qry_All_Ops.Operation)<>"Boat Transfer" And (Qry_All_Ops.Operation)<>"Diving"))
GROUP BY Qry_All_Ops.StartDate, Qry_All_Ops.Unit, Qry_All_Ops.Status
HAVING (((Count(Qry_All_Ops.Unit))>1) AND ((Qry_All_Ops.Status)="approved") AND ((Sum([Qry_All_Ops].[JettyNumber])/Count([Qry_All_Ops].[Unit])=CInt(Sum([Qry_All_Ops].[JettyNumber])/Count([Qry_All_Ops].[Unit])))=0));
Unfortunately the maths bit of it highlighted below...
Code:
[SumOfJettyNumber]/[CountOfUnit]
...is not cleaver enough to find all of the occasions where a Unit has been put in the wrong place.
I think I need to use CountOfUnit x JettyNumber <> SumOfJetty. If that equation is TRUE then there is a conflict, if FALSE then there isn't.
I think I can get this to work if I can get [JettyNumber] into the same query that I already have [CountOfUnit] & [SumOfJetty].
Any clues please ?
Reply With Quote
Sponsored Links
  #2  
Old 08-08-2007, 02:35 PM
Oscar_W Oscar_W is offline
Registered User
 
Join Date: Mar 2006
Location: Portsmouth
Posts: 42
Oscar_W is on a distinguished road
I have finally managed to get this to work but have to have one query based on another. Can anyone help me to combine these two below into one please ?

First one named Qry_Test
Code:
SELECT Qry_All_Ops.StartDate, Qry_All_Ops.Unit, First(Qry_All_Ops.JettyNumber) AS FirstOfJettyNumber, Last(Qry_All_Ops.JettyNumber) AS LastOfJettyNumber, Count(Qry_All_Ops.Unit) AS CountOfUnit, Sum(Qry_All_Ops.JettyNumber) AS SumOfJettyNumber
FROM Qry_All_Ops
WHERE (((Qry_All_Ops.Operation)<>"Diving" And (Qry_All_Ops.Operation)<>"Boat Transfer"))
GROUP BY Qry_All_Ops.StartDate, Qry_All_Ops.Unit, Qry_All_Ops.Status
HAVING (((Count(Qry_All_Ops.Unit))>1) AND ((Qry_All_Ops.Status)="approved"));
Second one named Qry_Test2
Code:
SELECT Qry_Test.StartDate, Qry_Test.Unit, [Qry_Test]![CountOfUnit]*[Qry_Test]![FirstOfJettyNumber]<>[Qry_Test]![SumOfJettyNumber] AS Expr1
FROM Qry_Test
WHERE ((([Qry_Test]![CountOfUnit]*[Qry_Test]![FirstOfJettyNumber]<>[Qry_Test]![SumOfJettyNumber])=-1));
This runs ok but would be much neater if I could combine them. Thanks.
Reply With Quote
Sponsored Links
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Calculations in Query. WhizzkidWallace Queries 2 01-26-2005 04:16 PM
Crosstable query returns too many records Palsam Queries 2 03-09-2004 11:41 AM
Calculations in a Query sedib Queries 1 09-09-2002 06:37 AM
Query to total calculations accross different queries. Cosmos75 Queries 5 08-27-2002 07:42 AM
Multi-Table Query and Calculations cinders Queries 2 08-28-2001 03:30 PM


All times are GMT -8. The time now is 05:33 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
(c) copyright 2009 Access World