SQL 取百分比

declare @cVale1 int
declare @cVale2 int
set @cVale1=100
set @cVale2=300

 

select cast(cast(0.89*100 as dec(18,2)) as varchar(10))+'%'  --89.00%
select 100/ 300  --0
select convert(decimal(10,2), @cVale1)/convert(decimal(10,2), @cVale2)  --0.3333333333333
select cast( (convert(decimal(10,2), @cVale1)/convert(decimal(10,2), @cVale2))*100 as dec(18,2)  ) --33.33
select  cast( cast( (convert(decimal(10,2), @cVale1)/convert(decimal(10,2), @cVale2))*100 as dec(18,2)) as varchar(10)) + '%'--33.33%

你可能感兴趣的:(sql)