Last active
March 1, 2016 12:54
-
-
Save luchosrock/963faed7c513102813f7 to your computer and use it in GitHub Desktop.
Formatear monto decimal a money con 4 decimales con separador de miles (.) y separador de decimales (,)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION FormatearMonto(@NumStr varchar(50)) | |
RETURNS Varchar(50) | |
AS | |
BEGIN | |
declare @OutStr varchar(50) | |
declare @i int | |
declare @run int | |
Select @i=CHARINDEX('.',@NumStr) | |
if @i=0 | |
begin | |
set @i=LEN(@NumStr) | |
Set @Outstr='' | |
end | |
else | |
begin | |
Set @Outstr=SUBSTRING(@NUmStr,@i,50) | |
Set @i=@i -1 | |
end | |
Set @run=0 | |
While @i>0 | |
begin | |
if @Run=3 | |
begin | |
Set @Outstr=','+@Outstr | |
Set @run=0 | |
end | |
Set @Outstr=SUBSTRING(@NumStr,@i,1) +@Outstr | |
Set @i=@i-1 | |
Set @run=@run + 1 | |
end | |
RETURN replace(replace(replace(replace(@OutStr,',','*'),'.','x'),'*','.'),'x',',') | |
--RETURN @OutStr | |
END | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment