Problem Dividing Values with float results

Renato Marcello dos Reis shared this question 6 years ago
Answered

Good morning guys,


I'm having a problem to create a report who counts 2 quantities of a related field. When the results come, the datatype is of course integer for both of then, because of the "Count" function used.


One of the values is always less than the other, and my problem is that I need to divide then by using the lesser value as the numerator and the greater value as the denominator. The result will always be 0 "Zero", because it's using the following query:


COUNT(CAST(COLUMN_NAME AS FLOAT)) / COUNT(CAST(COLUMN_NAME AS FLOAT))


The result would be correct if the syntaxe could by altered by the following


CAST(COUNT(COLUMN_NAME) AS FLOAT) / CAST(COUNT(COLUMN_NAME) AS FLOAT)


I've tried everything to acomplish this result, but I can't convert the result of an calculated field who's using an agregate function even when I tried to use SQL Freehand calculation. I can't use pre defined calculations either, because the 2 columns used in the calculation are from diferent subqueries, and the pre defined calculation can only use columns from the active query.


Can someone help me acomplish this result?


Thanks in advance.

Replies (1)

photo
1

Hi Renato,

I think your best bet here would be to include a *1.0 in your calculation which will implicitly cast all values in the operation to a float:

COUNT(COLUMN) * 1.0 / COUNT(COLUMN)

Let me know if this works for you.

Regards,

Nathan

photo
1

Hi Nathan,


It really worked. I appretiate your help in this case. Thanks a lot. Now I can use the same method on another calculations.

photo
1

Awesome! Glad to hear it. Let us know if you run into any problems.

Regards,

Nathan

photo
Leave a Comment
 
Attach a file