开发者

Efficient algorithm in t-sql to mimic int.ToString("D4");

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜