Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Show SQL Calculation as Percentage

Posted on 2007-11-23
Medium Priority
1,182 Views
I have this code

and when I run it it  sPercent shows as 0.

This is because the actual calcualtion is    12 / 80 = 0.15

so SQL rounds it off to 0

What I want to achieve is for sPercent to show 15%

Can anyone advise me on this?

Thanks

``````SELECT     dbo.tblBTLSurvey.NewBusinessQ1 + dbo.tblBTLSurvey.NewBusinessQ2 + dbo.tblBTLSurvey.NewBusinessQ3 AS total_score,
dbo.vwSurveyCount.CompletedSurveys
FROM         dbo.tblBTLSurvey CROSS JOIN
dbo.vwSurveyCount
``````
0
Question by:Ed
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 23

Assisted Solution

Ashish Patel earned 900 total points
ID: 20338133
Use this

0

LVL 23

Assisted Solution

Ashish Patel earned 900 total points
ID: 20338136
I mean for 15 %
just do this
Or or 15.00 %

0

LVL 23

Assisted Solution

Ashish Patel earned 900 total points
ID: 20338138
``````SELECT     dbo.tblBTLSurvey.NewBusinessQ1 + dbo.tblBTLSurvey.NewBusinessQ2 + dbo.tblBTLSurvey.NewBusinessQ3 AS total_score,
dbo.vwSurveyCount.CompletedSurveys
FROM         dbo.tblBTLSurvey CROSS JOIN
dbo.vwSurveyCount
``````
0

LVL 18

Expert Comment

ID: 20338140
Try 12 / 8.0
0

LVL 6

Expert Comment

ID: 20338166
Hi,

/ (Divide) operator in Books online:

If an integer dividend is divided by an integer divisor, the result is an integer that has any fractional part of the result truncated.

``````SELECT     dbo.tblBTLSurvey.NewBusinessQ1 + dbo.tblBTLSurvey.NewBusinessQ2 + dbo.tblBTLSurvey.NewBusinessQ3 AS total_score,
dbo.vwSurveyCount.CompletedSurveys
FROM         dbo.tblBTLSurvey CROSS JOIN
dbo.vwSurveyCount
``````
0

LVL 4

Accepted Solution

jindalankush earned 600 total points
ID: 20338256
during calculation convert any field  in float format
0

Author Comment

ID: 20338305

``````SELECT     dbo.tblBTLSurvey.NewBusinessQ1 + dbo.tblBTLSurvey.NewBusinessQ2 + dbo.tblBTLSurvey.NewBusinessQ3 AS total_score,
/ 80 AS varchar) + '%' AS sPercent, dbo.vwSurveyCount.CompletedSurveys
FROM         dbo.tblBTLSurvey CROSS JOIN
dbo.vwSurveyCount
``````
0

Author Closing Comment

ID: 31410648
solution

/ 80AS varchar) + '%' AS sPercent, dbo.vwSurveyCount.CompletedSurveys
FROM         dbo.tblBTLSurvey CROSS JOIN
dbo.vwSurveyCount
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question