如何生成从基数 000001 到 999999 或左填充的序列号?
如何在代码或查询中实现左填充。
FROM TO
1 000001
2 000002
10 000010
110 000110
1110 001110
99999 099999
我正在使用 MS Access 2007。
谢谢您的问候..
How to Implement LEFT Padding in Code or Query.
FROM TO
1 000001
2 000002
10 000010
110 000110
1110 001110
99999 099999
I am using MS Access 2007.
Thanks in Regards..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果要将数字格式化为带前导零的字符串,可以使用
d6
格式:示例:http://ideone.com/fScd9
If you want to format a number as a string with leading zeros, you can use the
d6
format:Example: http://ideone.com/fScd9
在 VBA 中,使用
Format$
函数(如果使用变体,请删除美元符号),并使用“000000”作为格式字符串。in VBA, use the
Format$
function (drop the dollar sign if you are using variants), and use "000000" for the format string.格式$(序列号,“000000”)
或
format(serial, "000000")
这会将字符串格式化为六位数字,在没有前导数字的情况下使用零。
format$(serial, "000000")
or
format(serial, "000000")
This will format the string to six digits using zeros where there are no leading numbers.
您还可以尝试
right(“000000”&serial,6)
。使用Format
更优雅,但是如果您在非常大的数据集或 ODBC 链接数据集上运行它,它可能会慢一些。You can also try
right("000000" & serial,6)
. UsingFormat
is more elegant, however if you are running this on really large datasets or ODBC linked datasets it can be quite a bit slower.