create function [dbo].[PadLeft] ( @input int ,@width int ,@pad char(1) ) returns varchar(max) as begin /* declare @input int = 1 ,@width int = 3 ,@pad char(1) = '0' */ declare @len int = case when @input = 0 then 1 else ceiling(LOG10(@input+1)) end declare @result varchar(max) = REPLICATE(@pad, @width - @len) + CONVERT(varchar(20), @input) /* select result = @result */ return @result end
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.