Link to home
Start Free TrialLog in
Avatar of Chris Millard
Chris MillardFlag for United Kingdom of Great Britain and Northern Ireland

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).

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'

Open in new window


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'

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chris Millard

ASKER

That's the jobbie!