Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
i have one table like this table1

SQL
sno   value1   value2
1      10000   11500
2      12000   13500


now i need to write query like this

SQL
select value1,value2,cast(((value1-value2)/value2)*100 as float) as Value3 from table1




i wrote like this but i am getting output like

SQL
value1   value2   value3
 10000    11500    0
 12000    13500    0


but in value3 column, i need to get values like
SQL
98.2,95.3


How can i get it? Please any one help me.
Posted
Updated 24-Mar-15 23:18pm
v2

Cast it as decimal(5,2)

declare 
	@v1 decimal(10,2),
	@v2 decimal(10,2)
	
set @v1 = 10000
set @v2 = 13500

select @v1 ,@v2 ,cast(((@v1-@v2)/@v2)*100 as decimal(5,2))


10000.00
13500.00
-25.93
 
Share this answer
 
v2
Hi,

Check this...

SQL
Select 
value1,
value2,
((CONVERT(DECIMAL(10,2),VALUE1) - CONVERT(DECIMAL(10,2),VALUE2)) / (CONVERT(DECIMAL(10,2),VALUE2)))*100 as VALUE3 
from table1




Hope this will help you.

Cheers
 
Share this answer
 

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