开发者

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

开发者 https://www.devze.com 2022-12-18 22:32 出处:网络
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:
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

精彩评论

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