displaying the field as a decimal in a sql query

How do I make the statement in query show as decimal. Currently it displays as 6. I want it to display as 6.43. Please let me know.

((SUM(CASE WHEN LDIS IN (100, 101,102,103,200,201,202,203,220,500,501,503,504,510,511,512,513,514,515,520,801,802,803,804,806,807,808,809,810) THEN 1 ELSE  0 END)*100)/ (count(*))) as rpcpercentage
mebster82Asked:
Who is Participating?
 
TempDBAConnect With a Mentor Commented:
As gestersGrind suggest just cast it as
cast(((SUM(CASE WHEN LDIS IN (100, 101,102,103,200,201,202,203,220,500,501,503,504,510,511,512,513,514,515,520,801,802,803,804,806,807,808,809,810) THEN 1 ELSE  0 END)*100.00)/ (count(*)))  as decimal(10,2))
0
 
jogosCommented:
0
 
TempDBACommented:
or while multiplying it with 100, multiply it with 100.00 instead.
0
 
JestersGrindCommented:
You're doing integer math.  That's the issue.  If you change the *100 to * 100.00 it will give you a decimal.  Then you can use CONVERT or CAST to limit the number of decimal places that you want.

Greg

0
 
mebster82Author Commented:
((SUM(CASE WHEN LDIS IN (100, 101,102,103,200,201,202,203,220,500,501,503,504,510,511,512,513,514,515,520,801,802,803,804,806,807,808,809,810) THEN 1 ELSE  0 END)*100.00)/ (count(*))) as rpcpercentage  

This works but it gives me a lot of decimals. How would i use the cast statement on above to make it only two decimals. Right now i get 4.955656565
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.