Funcion en SQL Server para ajustar un string a la derecha, llenandolo a la izquierda con ceros.
if object_id ( 'fnLeftPadWithZeros', 'FN' ) is not null
drop function fnLeftPadWithZeros
go
create function fnLeftPadWithZeros(@strInput varchar(max), @IntLenght smallint)
returns varchar(max)
as
begin
if @strInput is not null
begin
if len(@strInput) <= @IntLenght
begin
set @strInput = replicate('0', @IntLenght - len(ltrim(rtrim(@strInput)))) +
@strInput
end
end
return @strInput
end
go
-- PRUEBA DE LA FUNCION
declare @Text varchar(256)
set @Text = '1'
select Original = @Text
select SpacesRemoved = dbo.fnLeftPadWithZeros(@Text, 10)
go
--
Suscribirse a Comentarios de la entrada [Atom]
Suscribirse a
Entradas [Atom]