Solved

How to display the % sign with the returned results

Posted on 2012-04-12
7
257 Views
Last Modified: 2012-08-13
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
Comment
Question by:baxtalo
  • 4
  • 2
7 Comments
 
LVL 13

Expert Comment

by:Ashok
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

by:Ashok
Ashok earned 100 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

by:baxtalo
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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
LVL 13

Expert Comment

by:Ashok
ID: 37839117
In that case,  use

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

HTH
Ashok
0
 
LVL 13

Expert Comment

by:Ashok
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

by:
nishant joshi earned 400 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

Open in new window

0
 

Author Closing Comment

by:baxtalo
ID: 37839189
Thank you very much.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question