日期:2014-05-18 浏览次数:20622 次
create function rtrim0(@val numeric(10,2)) returns varchar(20) as begin return left(@val,len(@val)-patindex('%[^0]%.%',reverse(@val))+1) end go select dbo.rtrim0(12.20)
------解决方案--------------------
修正一下,1楼没考虑小数点后面全是0的情况
create function rtrim0(@val numeric(18,5)) returns varchar(20) as begin return case when @val=cast(@val as int) then ltrim(cast(@val as int)) else left(@val,len(@val)-patindex('%[^0]%.%',reverse(@val))+1) end end go select dbo.rtrim0(12.20)
------解决方案--------------------
declare @d decimal(10,2) set @d = 12.20 select convert(float,@d)