Skip to content

Instantly share code, notes, and snippets.

@FilipDeVos
Created May 13, 2011 08:21
Show Gist options
  • Save FilipDeVos/970195 to your computer and use it in GitHub Desktop.
Save FilipDeVos/970195 to your computer and use it in GitHub Desktop.
Strip trailing zeros
CREATE FUNCTION dbo.fn_strip_zeros(@number numeric(38,10))
RETURNS varchar(38)
WITH ENCRYPTION
AS
BEGIN
DECLARE @result varchar(38)
DECLARE @decimal varchar(3)
SET @decimal = substring(convert(varchar(38), convert(numeric(38,10),1)/5 ), 2,1)
set @result = rtrim(replace(replace(rtrim(replace(@number,'0',' ')),' ','0') + ' ', @decimal + ' ', ''))
RETURN @result
END
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment