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

Complex SUM statement giving erratic result! WHY!!!

Guest
Dec 26, 2009 Dec 26, 2009

Copy link to clipboard

Copied

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

Views

400

Translate

Translate

Report

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

Votes

Translate

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

Copy link to clipboard

Copied

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

Similarly,

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Am I writing this incorrectly?

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

Votes

Translate

Translate

Report

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
Documentation