• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

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
0
mebster82
Asked:
mebster82
1 Solution
 
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
 
TempDBACommented:
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now