/ * Get rid of more than 0 * / the CREATE the FUNCTION [ the dbo ] . [ Fn_ClearZero ] ( @inValue VARCHAR ( 50 ) ) the RETURNS VARCHAR ( 50 ) the AS the BEGIN the DECLARE @returnValue VARCHAR ( 20 is ); the IF ( @inValue = '' ) the SET @returnValue = '' ; - when empty to empty the ELSE the IF ( the CHARINDEX ('.', @inValue) = '0') SET @returnValue = @inValue; --针对不含小数点的 ELSE IF (SUBSTRING(REVERSE(@inValue), PATINDEX('%[^0]%', REVERSE(@inValue)), 1) = '.') SET @returnValue = LEFT(@inValue, LEN ( @inValue ) - the PATINDEX ( ' % [^ 0]% ' , REVERSE ( @inValue ))); - for all decimal 0 to the ELSE the SET @returnValue = the LEFT ( @inValue , LEN ( @inValue ) - the PATINDEX ( ' % [^ 0]%%. ' , REVERSE ( @inValue )) + . 1 ); - in any other case the RETURN @returnValue ; the END ; the GO
Excerpt from someone else's blog, a little long time could not find the original blog address -_- || ....