Skip to main content
December 27, 2009
Answered

Complex SUM statement giving erratic result! WHY!!!

  • December 27, 2009
  • 2 replies
  • 504 views

This part of my query;

SUM(totalSCs)+(totalCalls)+((TSLdays)*(WCG))/(5)/(QTCG) AS PerCalls

is giving me an erratic result...specifically 24.03 instead of .16

1 + 23 + (1 * 22) / 5) /176 = .16

Am I writing this incorrectly? Any assistance would be greatly appreciated!

This topic has been closed for replies.
Correct answer BKBK

(1 + 23 + (1 * 22 / 5)) /176 = 0.16...

Similarly,

(SUM(totalSCs) + totalCalls + (TSLdays*WCG/5))/QTCG AS PerCalls

2 replies

Inspiring
December 27, 2009

Am I writing this incorrectly?

Yes. As BKBK and editcorp mentioned, always use parenthesis to ensure the correct order of evaluation.

BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
December 27, 2009

(1 + 23 + (1 * 22 / 5)) /176 = 0.16...

Similarly,

(SUM(totalSCs) + totalCalls + (TSLdays*WCG/5))/QTCG AS PerCalls

Inspiring
December 27, 2009

Yep, the parenthesis makes all the difference.  Things are not evaluated left to right exclusively.  There is an order of operations http://en.wikipedia.org/wiki/Order_of_operations in which things are evaluated.  For CF, take a look at the

cfdocs: http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec09d55-7fff.html

(the link is for CF9, but I don't believe things have changed at all from prior versions).