473,385 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Issue with sum returning double the amount

Hi all, I'm having a serious issue with a sum returning double the amount it should.

I'm including the code below maybe you guys can see the problem:

Expand|Select|Wrap|Line Numbers
  1. SELECT clients.clientreadableid, Sum(projects.[total hours]) AS Hours
  2.  
  3.  
  4. FROM clients, projects, timesheet
  5.  
  6.  
  7. WHERE projects.clientreadableid=clients.clientid
  8. And projects.projectid=timesheet.projectreadableid 
  9.  
  10. And clients.clientid=forms![hours per client]!combo1 
  11.  
  12. And Month([sheetdate])=forms![hours per client]!combo3 
  13. And Year([sheetdate])=forms![hours per client]!text5
  14.  
  15. And InStr([typereadableid],"Abonament")>0 
  16.  
  17.  
  18. GROUP BY clients.clientreadableid;
Jan 11 '11 #1

✓ answered by Rabbit

Do you mean you get 10.5?

(1 project hour + 1.5 project hours) times 2 timesheets = 5 hours total.

(1 project hour + 1.5 project hours + 1 project hour) times 3 timesheets = 10.5 hours total.

You'll need to either return just one timesheet per project, or use a subquery to find the projects you need.

9 3374
Mr Key
132 100+
U may use a crosstab-Query to sum instead.
Jan 11 '11 #2
thanks for the reply, I'll try to do that but from what I'm seeing on the web it's somewhat complicated.

from what I've read on the web it's because of some strange join error meaning it basically just finds them twice
Jan 11 '11 #3
Rabbit
12,516 Expert Mod 8TB
What is the relationship between projects, clients, and timesheet? One-to-many? Many-to-many? One-to-one?
Jan 11 '11 #4
Hi Rabbit, thanks for the reply.

They are all many to many.
Jan 11 '11 #5
Rabbit
12,516 Expert Mod 8TB
There's the problem then. If one project has multiple timesheets, the project hours gets duplicated.

Can you show us some sample data? Choose one client, choose one project, and show us the relevant client data, project data, and all the timesheet data. Just the fields that are used in this query, we don't need to see any of the other fields.
Jan 11 '11 #6
don't exactly have the file here but let me give you a quick breakdown of fields.

clients table: clientreadableid is client name; clientid is autonumber. (ex: clientreadableid="Microsoft" clientid=80)
projects table: projectid is autonumber, [total hours] is number, typereadableid is project type, also autonumber FK for another table (ex: projectid = 10, total hours=2.5, typereadableid="Abonament")
timesheet table: [sheet date] is the date at which the timesheet is completed (ex: 10/01/2011)

that's all the fields that are used for this query and I find it weird that I'm getting this error, I've been checking and double-checking all day and nothing showed up as weird.

furthermore, i've been getting even weirder results.

for example with two timesheets of value 1 and 1.5 i get
a sum of 5 but if i add another value of 1 the sum jumps to 11.5.

I'll try to do the sum on timesheets rather than project hours, see if that helps. But that'll have to wait until morning.
Jan 11 '11 #7
Rabbit
12,516 Expert Mod 8TB
Do you mean you get 10.5?

(1 project hour + 1.5 project hours) times 2 timesheets = 5 hours total.

(1 project hour + 1.5 project hours + 1 project hour) times 3 timesheets = 10.5 hours total.

You'll need to either return just one timesheet per project, or use a subquery to find the projects you need.
Jan 11 '11 #8
yes, I'm sorry, 10.5 is right, i remembered it incorrectly. odd thing is that only the ones under category "abonament get multiplied", even in a normal query (without instr).

so for 3.5 abon i get 10.5 hours
but for 3.5 abon and 1 dd i get 11.5 hours

quite odd.

wow, i actually solved it. by counting the hours in the timesheet rather than the hours in the project it now returns the proper value.

thanks again for all the help and helping me figure this out!
Jan 12 '11 #9
Rabbit
12,516 Expert Mod 8TB
No problem, good luck.
Jan 12 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ram Naresh Talluri | last post by:
Hi, I have huge data to print arround 1lakh recod on one streach . I given it directly to print by using javascript function Window.Print(); But the application hang I used tr's... to view the...
20
by: Martijn | last post by:
Hi, Those familiar with Windows programming may be familiar with the windowsx.h header. In this header macros exist that use double casts, like so (hope this is readable): #define...
2
by: Asha | last post by:
hello, every time i refresh my page i get a double entry? how can i solve this issue?
3
by: kamran | last post by:
Hi, I have a web service that may return a very large amount of data. I want that data to return in chunks, like first return 10% of data than return the next 10% and so on, until all is...
1
by: veaux | last post by:
I'm using Access query and have to spit out a text file to load into a 3rd party program. The text file has to include quotes (" ") around certain infomation. The string I have is below. ...
8
by: SK | last post by:
Hello all, I need to pass a string to a sql procedure in this fashion <DateParam> <BeginDate="2007-01-25" BeginTime="08:30 AM" EndTime="09:45AM"/> </DateParam> If you notice the date and time...
5
by: Seb | last post by:
Hi, We have a page in VB.NET redirecting to an external site. Example: http://mysite.com/redirect.aspx?url=http//externalsite.com/their-page.asp The target page on the external site...
2
by: clintonb | last post by:
Victor said: The double value that I'm trying to convert to GCSMoney (which is implemented as cents) was produced by multiplying a dollar amount by an interest rate to get interest. double...
5
by: blt51 | last post by:
I need to write a program that handles a bank account and does a number of transactions using an arraylist. However, I'm having trouble getting the arraylist to store all the transactions and then...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.