Solved

How to display the % sign with the returned results

Posted on 2012-04-12
7
255 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now