Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

How to display the % sign with the returned results

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
baxtalo
Asked:
baxtalo
  • 4
  • 2
2 Solutions
 
AshokCommented:
Do you want this result to be saved in Excel file with formatted column?

like 1.25%

Ashok
0
 
AshokCommented:
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
 
baxtaloAuthor Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
AshokCommented:
In that case,  use

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

HTH
Ashok
0
 
AshokCommented:
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
 
nishant joshiTechnology Development ConsultantCommented:
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
 
baxtaloAuthor Commented:
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.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now