Solved

How to display the % sign with the returned results

Posted on 2012-04-12
7
259 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

739 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