views:

84

answers:

2
int i=99;
string s=i.ToString("D4");
//s=="0099"

Please advice on efficient implementation of preceding zeroes of numbers in textual format.

+3  A: 

usually i do sth like:

RIGHT('0000' + [col], 4)
Andreas Niedermair
A: 

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
TonyP