现在的位置: 首页 > 综合 > 正文

转换数字为指定长度的字符串,前面补0 的SQL

2012年02月29日 ⁄ 综合 ⁄ 共 256字 ⁄ 字号 评论关闭

use jktj_net
right('00000'+cast(@count as varchar),5)
--'00000'的个数为right函数的最后参数,例如这里是5,所以有5个0
--@count就是被格式化的正整数
--同时,给出个有趣的测试办法,在查询分析里运行就能看到结果

declare @count int
set @count = 0
while (@count < 1000)
begin
print right('0000000000'+cast(@count as varchar),10)
set @count = @count +1
end

抱歉!评论已关闭.