nidhi
nidhi

Reputation: 35

How to display output with a % sign. eg: 90%

the below query gives me result as 90 AND NOT 90%.

SELECT
 CAST(convert(decimal(20,10),[Total]) as int) AS 'TT'
,cast((convert(decimal(20,10),([Count_Checked_Out]/convert(decimal(20,10),[Total])))* 100) as int) AS '%_Checked_Out'

Upvotes: 0

Views: 75

Answers (2)

Shubham Srivastava
Shubham Srivastava

Reputation: 1877

If you want to do this in sql query you can do something like this

select concat(90,"%") as percent_value;

But as @Joel Coehoom pointed out you should do this in your presentation layer

http://sqlfiddle.com/#!9/9eecb/191808/0

Upvotes: 0

Joel Coehoorn
Joel Coehoorn

Reputation: 416039

If you want formatting, of any kind, you must convert the value from a number type, like int, to a string type, like nvarchar. Exactly what this looks like depends on what specific database platform you're using.

But in most cases, you're better off leaving this work for your client code or reporting tool.

Upvotes: 2

Related Questions