Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
select EName,Basic,PF,PF/Basic*100 as [PF Percentage] from Emp where EName='John'


Result :

EName    Basic   PF      PF Percentage
John     1000    100         10

But I want to display
PF Percentage
   10 %


Can i write

SQL
select EName,Basic,PF,PF/Basic*100+'%' as [PF Percentage] from Emp where EName='John'


Thanks
Posted
Updated 9-Dec-14 18:15pm
v3
Comments
PIEBALDconsult 10-Dec-14 0:17am    
You would have to cast it to character first, but that's really a task for the reporting system.

hi ,

try this
SQL
Select EName,Basic,PF,CAST(PF/Basic*100 as varchar(20)) + '%' as [PF Percentage] from Emp where EName='John'
 
Share this answer
 
v2
select convert(varchar(10), PF/basic * 100) + '%' as [PF Percentage] from applicationInfo
 
Share this answer
 
Before that you have to cast your column to character,try like this
you can set varchar limt as per your needs,
SQL
select EName,Basic,PF,cast(PF/Basic*100 as varchar(50))+'%' as PF_Percentage from Emp where EName='John'
 
Share this answer
 
v2
Comments
/\jmot 10-Dec-14 3:17am    
varchar??? varchar(length)??
Rajesh waran 10-Dec-14 4:15am    
Thanks for intimating me,forgot to set limit. Now i updated my solution
Didn't you try..
SQL
select '%'

here we are getting a string '%', and we know that we can con-cat any string to String result set in sql.


We know Simple Query....
SQL
Select column1,colum2,column3.. from table_Name1


If we want to Add any String to the Result set, what we do..??
i think. like this..
SQL
Select cast(isnull(column1,'') as varchar(50))+'%',cast(isnull(colum2,'') as varchar(50)+'%',column3.. from table_Name1


here
SQL
'%'
is the string value we are adding with the result set from table.

in your case..
SQL
select EName,Basic,PF,(cast((PF/Basic*100) as varchar(50))+'%') as [PF Percentage] from Emp where EName='John'

Hope, it'll help you.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900