int i=99;
string s=i.ToString("D4");
//s=="0099"
Please advice on efficient implementation of preceding zeroes of numbers in textual format.
int i=99;
string s=i.ToString("D4");
//s=="0099"
Please advice on efficient implementation of preceding zeroes of numbers in textual format.
You could use the funcion defined below
select dbo.fsPadLeft(@i,'0',4)
or inline statement Select replicate(x,4-Len(x))+x from y
Create Function [dbo].[fsPadLeft](@var varchar(200),@padChar char(1)='0',@len int)
returns varchar(300)
as
Begin
return replicate(@PadChar,@len-Len(@var))+@var
end