int i=99;
string s=i.ToString("D4");
//s=="0099"
Please advice on 开发者_Go百科efficient implementation of preceding zeroes of numbers in textual format.
usually i do sth like:
RIGHT('0000' + [col], 4)
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
精彩评论