Monday, March 19, 2012

Convert to float value

Hi guys, the following is the part of my query that I am having an issue.

Select....

.....

,100 * count(c_id)/(select count(c_id) From tbl_comp c,tbl_empl e where c.c_type = 'b' and c.e_id = e.e_id ) AS [Perc]

,....

From.....

Where...

That part of the statement should have to give me FLOAT values, such as 60.99 etc. however, it is giving me only the integer part (i.e. 60). I tried to cast/convert the values to float value but I coudn't.

Any idea?

Try changing

,100 * count(c_id)/(select count(c_id) From tbl_comp c,tbl_empl e where c.c_type = 'b' and c.e_id = e.e_id ) AS [Perc]

to

,100 * cast(count(c_id) as float)/(select count(c_id) From tbl_comp c,tbl_empl e where c.c_type = 'b' and c.e_id = e.e_id ) AS [Perc]

|||

Perfect!

my bad, what I did befor is

CAST(100 * count(c_id)/(select count(c_id) From tbl_comp c,tbl_empl e where c.c_type = 'b' and c.e_id = e.e_id ) AS FLOAT) AS [Perc]

|||

You can also use a higher precedence data type in the formula.

100.00 * count(c_id)/(select count(c_id) From tbl_comp c,tbl_empl e where c.c_type = 'b' and c.e_id = e.e_id ) AS [Perc]

AMB

|||Cool! that is also working.

No comments:

Post a Comment