Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# How to display the % sign with the returned results

Posted on 2012-04-12
Medium Priority
262 Views
I'd like to have the % sign displayed when the query below returns the percentage results. How can that be accomplished? Thanks for your help.

declare @total decimal
select @total = COUNT(*)
FROM [myDatabase].[dbo].[myTable]

Select COUNT(*) as [Count], cast(COUNT(*)/@total*100 as numeric(10,0)) as [Percentage], Letter
FROM [myDatabase].[dbo].[myTable]
group by Letter
0
Question by:baxtalo
[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
• 4
• 2

LVL 13

Expert Comment

ID: 37839049
Do you want this result to be saved in Excel file with formatted column?

like 1.25%

Ashok
0

LVL 13

Assisted Solution

Ashok earned 400 total points
ID: 37839108
if you want it in SELECT statement.....

SELECT CONVERT(VARCHAR(50),yourNumericCol*100)+ '%' as PercentWithConvert, CAST(yourNumericCol*100 AS VARCHAR(50))+ '%' as PercentWithCAST
FROM numericTable

HTH
Ashok
0

Author Comment

ID: 37839109
No, I just want to display a pie chart on a web page. Right now it displays the pie chart, but it doesn't have the % sign after the numbers.
0

LVL 13

Expert Comment

ID: 37839117
In that case,  use

SELECT
CAST(yourNumericCol*100 AS VARCHAR(50))+ '%' as PercentWithCAST
FROM numericTable

HTH
Ashok
0

LVL 13

Expert Comment

ID: 37839127
Try

Select COUNT(*) as [Count], cast(COUNT(*)/@total*100 as VARCHAR(50))+ '%' as [Percentage], Letter
FROM [myDatabase].[dbo].[myTable]
group by Letter;

HTH
Ashok
0

LVL 14

Accepted Solution

nishant joshi earned 1600 total points
ID: 37839137
check below code.
`````` declare @total decimal
select @total = COUNT(*)
FROM [myDatabase].[dbo].[myTable]

Select COUNT(*) as [Count], cast((cast(COUNT(*)/@total*100 as numeric(10,0))) as varchar(100))+'%' as [Percentage], Letter
FROM [myDatabase].[dbo].[myTable]
group by Letter
``````
0

Author Closing Comment

ID: 37839189
Thank you very much.
0

## Featured Post

Question has a verified solution.

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