Solved

How to display the % sign with the returned results

Posted on 2012-04-12
7
260 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
[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
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 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