Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Expert 32    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
CLNGAVG Potential Problems
Hendra Gunawan 
     
3 years ago
Lesson 3: 6m54s

In lesson 3, we need to convert the AVG(NumEmployees) function to Long Integer by using CLNG (AVG(NumEmployees)) because if we don't, there will be a mismatch data type. NumEmployees is a long integer but AVG returns a double.

I think there is potential problem with this approach.

See FIGURE 1:
Let's say you have 9 customers whose NumEmployees are
1, 1, 1, 2, 2, 2, 2, 3, 3. The AVG is 1.89. If you convert this to long integer, you will get 2. And if you run the subquery >(SELECT CLNG(AVG([NumEmployees])) FROM CustomerT), the query will return two customers whose NumEmployees are 3 and 3. This is incomplete. The average 1.89. There are employees who have 2 employees each. But they are not listed in the query because we convert the average from 1.89 to 2 (rounding error). So, the query looks for NumEmployees > 2, instead of > 1.89.

Now see FIGURE 2:
Instead of converting the AVG to double, why not change the NumEmployees from Long Integer to Double in CustomerT and this time do not convert AVG to long integer.
That way the precision of every number is preserved. There will be no rounding error.
Hendra Gunawan OP  @Reply  
     
3 years ago

Hendra Gunawan OP  @Reply  
     
3 years ago

Richard Rost  @Reply  
          
3 years ago
I would calculate that average first into a Double, and then base your SQL on that.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Expert 32.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 7/5/2026 6:51:01 PM. PLT: 1s