比如12.20,s?q?l中有这样的函数吗?
------解决方案--------------------
- SQL code
create function rtrim0(@val numeric(10,2)) returns varchar(20)asbegin return left(@val,len(@val)-patindex('%[^0]%.%',reverse(@val))+1)endgoselect dbo.rtrim0(12.20)
------解决方案--------------------
修正一下,1楼没考虑小数点后面全是0的情况
- SQL code
create function rtrim0(@val numeric(18,5)) returns varchar(20)asbegin return case when @val=cast(@val as int) then ltrim(cast(@val as int)) else left(@val,len(@val)-patindex('%[^0]%.%',reverse(@val))+1) endendgoselect dbo.rtrim0(12.20)
------解决方案--------------------
- SQL code
declare @d decimal(10,2) set @d = 12.20select convert(float,@d)