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

Rounding Up

Participant ,
Nov 18, 2009 Nov 18, 2009

I am doing a simple calculation and need to round up the output :

Here is my partial query :

SELECT SUM(cycleTime) / COUNT(urdn_number) AS ceiling(cycleTime), count(urdn_number) as totalCount,
  sum(totalValue) as totalCost, Month_Status
   FROM
   ( 
   SELECT distinct a.urdn_number,
   DATEDIFF(day, a.Date_Arrived, b.activity_date) + 1 AS cycleTime,

The cycle time variable needs to round up but it keeps rounding down. What am I doing wrong ? I even had the ceiling before the sum but that still did not work.

For example, my numbers are 206/14 = 14.7 and should round p to 15 but I still get 14 as my output.

Please help, driving me nuts.

TOPICS
Getting started
777
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

Valorous Hero , Nov 18, 2009 Nov 18, 2009

If worse comes to worse just select the two components and do the calculation in the output.

<cfquery name="stuff"...>

SELECT SUM(cycleTime), COUNT(urdn_number)...

...

</cfquery>

<cfoutput query="stuff"...>

#ceiling(cycleTime/urdn_number)#


</cfoutput>

Translate
Advisor ,
Nov 18, 2009 Nov 18, 2009

It looks like the SELECT portion of your query may be the problem.  Try moving the the call to the ceiling function to surround the value in question.

SELECT
     ceiling( SUM(cycleTime) / COUNT(urdn_number) ) AS cycleTime,
    count(urdn_number) as totalCount,
      sum(totalValue) as totalCost, Month_Status

Have you also verified that your database supports the ceiling function?

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
Enthusiast ,
Nov 18, 2009 Nov 18, 2009

is this sql server? if so, are any of the columns used in your calculations int

data type? sql server will always default to the lowest common denominator, ie

if you do

real_column / int_column

you get back an int result. try casting the int column to real or multiplying by

1.00 to let sql server you want to use reals (or whatever).

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
Participant ,
Nov 18, 2009 Nov 18, 2009

I tried moving the ceiling to the sum and it still did not work.

I even tried #ceiling(cycleTime)# in the output and that did not work either.

I am on SQL and it has a ceiling and/or round fucntion, I gooled it. But still cannot get it to work.

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 ,
Nov 18, 2009 Nov 18, 2009
LATEST

If worse comes to worse just select the two components and do the calculation in the output.

<cfquery name="stuff"...>

SELECT SUM(cycleTime), COUNT(urdn_number)...

...

</cfquery>

<cfoutput query="stuff"...>

#ceiling(cycleTime/urdn_number)#


</cfoutput>

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 ,
Nov 18, 2009 Nov 18, 2009

Does your database have a ceiling or similar function?

Doing it as you have here is not going to work.  You are just naming the results with a column name "ceiling(cycleTime)"

If you can not do this in the database, it should be pretty easy to do it in the output with ColdFusion functions.

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