Demand:
For numeric information with a decimal point, remove the extra 0 after the decimal point
Possible situations:
1, the accuracy of the range, the presence of excess 0 eg:1234.3400 desired result is 1234.34
2, the accuracy of the larger appearance of the excess 0, or no actual fractional part of the data eg:1234.0 want the result of 1234
3, the end of the data is a decimal point, but there is no actual decimal eg:1234. The desired result is 1234
----Go to 0 function---Remove the extra 0 select dbo after the decimal point. Clearzero (' 1245.3400 ')---result is 1245.34Create function [dbo].[Clearzero](@Number varchar( $))returns varchar( $) asbegin if @Number = "' or @Number is NULL ---if empty, return directly return NULL Else begin Declare @PointIndex int Set @PointIndex = charindex('.',@Number) if @PointIndex = 0 return @Number ---If it is not a floating-point number, return directly if @PointIndex = Len(@Number)return Replace(@Number,'.',"')----decimal points at the end of the number, directly delete the return Else begin if Right(@Number,1)= '0' ---Recursive call, go to 0 operation begin Set @Number = substring(@Number,1,Len(@Number)- 1) returnDbo. Clearzero (@Number) End Else return @Number End End return NULLEndGO
Number of SQL Server classic functions go to 0