Jump to content
  • 0

Calculated field returning 0


techguy

Question

I have a calculated field. I am trying to divide two queries. By themselves the work. But when I try to divide them to get a percentage it always returns 0

Calculated Field

(SELECT count(Director1) FROM shareholders WHERE Director1>0)    returns correct count

(SELECT count(Email) FROM shareholders)  returns correct count

 

(SELECT count(Director1) FROM shareholders WHERE Director1>0)/(SELECT count(Email) FROM shareholders)   ALWAYS ZERO

 

I have verified that the number has decimals set to 2, it will not calculate

 

Any suggestions to divide these? 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
34 minutes ago, techguy said:

I have a calculated field. I am trying to divide two queries. By themselves the work. But when I try to divide them to get a percentage it always returns 0

Calculated Field

(SELECT count(Director1) FROM shareholders WHERE Director1>0)    returns correct count

(SELECT count(Email) FROM shareholders)  returns correct count

 

(SELECT count(Director1) FROM shareholders WHERE Director1>0)/(SELECT count(Email) FROM shareholders)   ALWAYS ZERO

 

I have verified that the number has decimals set to 2, it will not calculate

 

Any suggestions to divide these? 

convert the values to FLOAT to get a value. The problem is because both are returning integers due to COUNT(). so it is actually computing right but is returning whole numbers only.

CONVERT(FLOAT, (SELECT count(Director1) FROM shareholders WHERE Director1>0))/CONVERT(FLOAT, (SELECT count(Email) FROM shareholders))

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...