4 Replies Latest reply on Dec 27, 2009 9:06 PM by emartek1

# Complex SUM statement giving erratic result! WHY!!!

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!

• ###### 1. Re: Complex SUM statement giving erratic result! WHY!!!

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

Similarly,

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

• ###### 2. Re: Complex SUM statement giving erratic result! WHY!!!

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

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

• ###### 3. Re: Complex SUM statement giving erratic result! WHY!!!

Am I writing this incorrectly?

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

• ###### 4. Re: Complex SUM statement giving erratic result! WHY!!!

Thanks BKBK and everyone else who responded. The parentheses were the key!