Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Complex SUM statement giving erratic result! WHY!!!

Guest
Dec 26, 2009 Dec 26, 2009

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!

TOPICS
Advanced techniques
464
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 27, 2009 Dec 27, 2009

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

Similarly,

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

Translate
Community Expert ,
Dec 27, 2009 Dec 27, 2009

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

Similarly,

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 27, 2009 Dec 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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 27, 2009 Dec 27, 2009
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Dec 27, 2009 Dec 27, 2009

Am I writing this incorrectly?

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources