Chris Millard
asked on
SQL SUM giving unexpected results
I am getting some unexpected results when running a SUM on a SQL database. The database is used by a 3rd party program, and I've written my own program to extract some data.
The 3rd party program is a helpdesk system, and logs technician times against jobs. The technician actions are logged as either billable or non billable.
I need to add together the amount billable hours and non-billable hours for the current month on a per-technician basis.
Here's the problem. If I run two separate queries - one to get the billable hours and one to get the non-billable hours then in my program, add the results together, I get the answer I am expecting (in this instance 177.77).
If I try to perform the addition in my SQL statment, my answer comes back as 174.27 and I don't know how to troubleshoot the problem...
The 3rd party program is a helpdesk system, and logs technician times against jobs. The technician actions are logged as either billable or non billable.
I need to add together the amount billable hours and non-billable hours for the current month on a per-technician basis.
Here's the problem. If I run two separate queries - one to get the billable hours and one to get the non-billable hours then in my program, add the results together, I get the answer I am expecting (in this instance 177.77).
SELECT SUM(timetaken) FROM dbo.ACTIONS where who='Tech1' and When >= '08/01/2012'
SELECT SUM(nonbilltime) FROM dbo.ACTIONS where who='Tech1' and When >= '08/01/2012'
If I try to perform the addition in my SQL statment, my answer comes back as 174.27 and I don't know how to troubleshoot the problem...
SELECT SUM(timetaken + nonbilltime) FROM dbo.ACTIONS where who='Tech1' and When >= '08/01/2012'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER