I am getting the averages of a field LT. When I run it in the query
designer:
SELECT tbl_LTandWait.EngModule, Avg(tbl_LTandWait.LT) AS AvgOfLT,
Avg(tbl_LTandWait.LT_Mfg) AS AvgOfLT_Mfg
FROM tbl_LTandWait
WHERE (((tbl_LTandWait.EngSN)<>' Median LT' And
(tbl_LTandWait.EngSN)<>' Lead Time Goal' And (tbl_LTandWait.EngSN)<>'
Avg Lead Time'))
GROUP BY tbl_LTandWait.EngModule
HAVING (((tbl_LTandWait.EngModule)='Horizontal'));
I get the AvgOfLT as 3.916 which is correct.
When I do it in code:
lsSQL = "SELECT tbl_LTandWait.EngModule, Avg(tbl_LTandWait.LT) AS
AvgOfLT, Avg(tbl_LTandWait.LT_Mfg) AS AvgOfLT_Mfg " & _
"FROM tbl_LTandWait " & _
"WHERE (((tbl_LTandWait.EngSN)<>' Median LT' And
(tbl_LTandWait.EngSN)<>' Lead Time Goal' And (tbl_LTandWait.EngSN)<>'
Avg Lead Time')) " & _
"GROUP BY tbl_LTandWait.EngModule " & _
"HAVING (((tbl_LTandWait.EngModule)='Horizontal'))"
Set dbs = CurrentDb
Set rstMods = dbs.OpenRecordset(lsSQL)
MsgBox rstMods!AvgOfLT
Exit Sub
I get 3.57 which is wrong. It is exactly the same query whether in code
or query so I don't understand why I get different results.
Anbody have any ideas.
Thanks,
Steeler 2 1301
Steeler wrote:
I am getting the averages of a field LT. When I run it in the query
designer:
SELECT tbl_LTandWait.EngModule, Avg(tbl_LTandWait.LT) AS AvgOfLT,
Avg(tbl_LTandWait.LT_Mfg) AS AvgOfLT_Mfg
FROM tbl_LTandWait
WHERE (((tbl_LTandWait.EngSN)<>' Median LT' And
(tbl_LTandWait.EngSN)<>' Lead Time Goal' And (tbl_LTandWait.EngSN)<>'
Avg Lead Time'))
GROUP BY tbl_LTandWait.EngModule
HAVING (((tbl_LTandWait.EngModule)='Horizontal'));
I get the AvgOfLT as 3.916 which is correct.
When I do it in code:
lsSQL = "SELECT tbl_LTandWait.EngModule, Avg(tbl_LTandWait.LT) AS
AvgOfLT, Avg(tbl_LTandWait.LT_Mfg) AS AvgOfLT_Mfg " & _
"FROM tbl_LTandWait " & _
"WHERE (((tbl_LTandWait.EngSN)<>' Median LT' And
(tbl_LTandWait.EngSN)<>' Lead Time Goal' And (tbl_LTandWait.EngSN)<>'
Avg Lead Time')) " & _
"GROUP BY tbl_LTandWait.EngModule " & _
"HAVING (((tbl_LTandWait.EngModule)='Horizontal'))"
Set dbs = CurrentDb
Set rstMods = dbs.OpenRecordset(lsSQL)
MsgBox rstMods!AvgOfLT
Exit Sub
I get 3.57 which is wrong. It is exactly the same query whether in code
or query so I don't understand why I get different results.
Anbody have any ideas.
Thanks,
Steeler
I suppose you could save the query created in the query designer as,
say, "query2", or whatever and then use something like:
Dim isSQL As String
isSQL = DBEngine(0)(0).QueryDefs("query2").SQL
Debug.Print DBEngine(0)(0).OpenRecordset(isSQL)!AvgOfLT
to ensure that no syntax error has been made.
Steeler wrote:
I am getting the averages of a field LT. When I run it in the query
designer:
SELECT tbl_LTandWait.EngModule, Avg(tbl_LTandWait.LT) AS AvgOfLT,
Avg(tbl_LTandWait.LT_Mfg) AS AvgOfLT_Mfg
FROM tbl_LTandWait
WHERE (((tbl_LTandWait.EngSN)<>' Median LT' And
(tbl_LTandWait.EngSN)<>' Lead Time Goal' And (tbl_LTandWait.EngSN)<>'
Avg Lead Time'))
GROUP BY tbl_LTandWait.EngModule
HAVING (((tbl_LTandWait.EngModule)='Horizontal'));
I get the AvgOfLT as 3.916 which is correct.
When I do it in code:
lsSQL = "SELECT tbl_LTandWait.EngModule, Avg(tbl_LTandWait.LT) AS
AvgOfLT, Avg(tbl_LTandWait.LT_Mfg) AS AvgOfLT_Mfg " & _
"FROM tbl_LTandWait " & _
"WHERE (((tbl_LTandWait.EngSN)<>' Median LT' And
(tbl_LTandWait.EngSN)<>' Lead Time Goal' And (tbl_LTandWait.EngSN)<>'
Avg Lead Time')) " & _
"GROUP BY tbl_LTandWait.EngModule " & _
"HAVING (((tbl_LTandWait.EngModule)='Horizontal'))"
Set dbs = CurrentDb
Set rstMods = dbs.OpenRecordset(lsSQL)
MsgBox rstMods!AvgOfLT
Exit Sub
I get 3.57 which is wrong. It is exactly the same query whether in code
or query so I don't understand why I get different results.
Anbody have any ideas.
Thanks,
Steeler
It almost sounds like 1 query is returning more records than the other
when avg'ing. Maybe make a copy and remove the grouping/avging thus
making it a Select query instead of a totals query and see if they both
return the same number of records. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: sql-db2-dba |
last post by:
We have DB2 UDB v8.1 fixpak3 on AIX 5. Production and Development
configuarations (at least for DB2) are identical albeit production is
a 2-way server while development has only one processor....
|
by: 73blazer |
last post by:
We are migrating a customer from Version 7.1 FP3, to Version 8.2 (8.1 FP8).
For the most part, things are faster, but there is one query that is
much much slower, and it is a query that is used all...
|
by: sausage31 |
last post by:
I have a table as follows....
Device LotID Result1 Result2 Result3
aaa 1 5 10 15
bbb 1 2 4 6
aaa 2 ...
|
by: Randy Harris |
last post by:
How can I report an average of non zero values?
If the values are:
5, 0, 6, 0, 4
I would like the result 5 (15 / 3), not 3 (15 / 5)
Thanks for any help...
|
by: Pea |
last post by:
Is it possible to get the average in a query where I have multiple
criteria?
Here's an abbreviated example of the query in design view:
Fields: USERID DATE TIME ID_TYPE...
|
by: Tina |
last post by:
My employer tracks productivity/performance of clinicians (how much
they
bill) each week, its averages for the month, and the 6 months.
These averages are compared to their expected productivity....
|
by: santoni |
last post by:
I really need help me with this. I'm sure it's really easy for most. I
really appreciate any help. Thanks!
I have tables Employee and Sales. In Employees the yes/no field
IsManager denotes...
|
by: RCapps |
last post by:
When running the below SQL Query I keep getting the following error:
Server: Msg 4924, Level 16, State 1, Line 1
ALTER TABLE DROP COLUMN failed because column 'ContractDef' does not exist in table...
|
by: Jon Skeet [C# MVP] |
last post by:
On Sep 9, 9:41 am, raylopez99 <raylope...@yahoo.comwrote:
It's tricky in .NET for two reasons:
1) LINQ doesn't have any concept of "remove"
2) List<T>.RemoveAll doesn't pass in the index...
|
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
|
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...
|
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...
|
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...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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,...
| |