如何生成从基数 000001 到 999999 或左填充的序列号?

发布于 2024-10-09 20:13:31 字数 233 浏览 0 评论 0原文

如何在代码或查询中实现左填充。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

听风吹 2024-10-16 20:13:31

如果要将数字格式化为带前导零的字符串,可以使用 d6 格式:

int i = 200;
Console.Write(i.ToString("d6")); // prints 000200

示例:http://ideone.com/fScd9

If you want to format a number as a string with leading zeros, you can use the d6 format:

int i = 200;
Console.Write(i.ToString("d6")); // prints 000200

Example: http://ideone.com/fScd9

海未深 2024-10-16 20:13:31

在 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.

泪是无色的血 2024-10-16 20:13:31

格式$(序列号,“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.

信愁 2024-10-16 20:13:31

您还可以尝试right(“000000”&ser​​ial,6)。使用Format 更优雅,但是如果您在非常大的数据集或 ODBC 链接数据集上运行它,它可能会慢一些。

SELECT [serial], right("000000" & [serial],6) AS [PaddedSerial]
FROM Table1

You can also try right("000000" & serial,6). Using Format is more elegant, however if you are running this on really large datasets or ODBC linked datasets it can be quite a bit slower.

SELECT [serial], right("000000" & [serial],6) AS [PaddedSerial]
FROM Table1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文