截掉记录前面的0

发布于 2025-01-02 23:26:17 字数 573 浏览 5 评论 0原文

这可能是一个基本问题,但我不知道如何在谷歌中表达它。

基本上,我有一个 Access 数据库,其主键采用这种格式(“02”000)构造。

当我尝试粘贴数字时,它会忽略“02”并直接转到 000。

例如,这是代码;

PeriodRoomID.Name = ("R" & ds.Tables("sqlSpecRoomRequest").Rows(i).Item(1))

periodRoomID.Name 应该是 R02001。 出现的PeriodRoomID.Name 是R1。

它忽略“02”并忽略 0。这在数学上是有意义的,但这不是我想要的。我需要一种方法来获得准确的输出,而不是一些简化的版本。

查询;

SELECT SpecialSoftware.SpecSoftID, SpecialSoftware.RoomID, SpecialSoftwareNames.Description, Rooms.Capacity
FROM SpecialSoftware, SpecialSoftwareNames, Rooms

This may be a basic question but I have no idea on how to word it in Google.

Basically, I have an Access database with Primary keys that are structured with this format ("02"000).

When I try to paste the number, it ignores the "02" and goes straight to 000.

For example, here is the code;

PeriodRoomID.Name = ("R" & ds.Tables("sqlSpecRoomRequest").Rows(i).Item(1))

What PeriodRoomID.Name should be is R02001.
What PeriodRoomID.Name comes up as is R1.

It ignores the "02" and ignores the 0s. This makes sense mathematically but it is not what I want. I need a way to get the exact output and not some simplified version.

The query;

SELECT SpecialSoftware.SpecSoftID, SpecialSoftware.RoomID, SpecialSoftwareNames.Description, Rooms.Capacity
FROM SpecialSoftware, SpecialSoftwareNames, Rooms

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

谈场末日恋爱 2025-01-09 23:26:17

您可以在应用程序内格式化数字:

Dim roomID As String = ds.Tables("sqlSpecRoomRequest").Rows(i).Item(1)
PeriodRoomID.Name = "R02" & roomID.PadLeft(3, "0"c)

You could just format the number inside your app:

Dim roomID As String = ds.Tables("sqlSpecRoomRequest").Rows(i).Item(1)
PeriodRoomID.Name = "R02" & roomID.PadLeft(3, "0"c)
红尘作伴 2025-01-09 23:26:17

我建议您将自动编号字段的格式设置为“02”000。该格式所做的只是以该格式向 Access 用户显示数据。该字段不包含 02001,它包含 1。如果您希望重新创建格式,则必须在应用程序中执行此操作。将自动编号更新为 n 将在 ADO 和 ODBC 中显示为 n,但在 Access 中的各个位置显示为 0200n - 这种格式甚至与 Access 中的查询无关。我不认为表格中的格式是一个好主意。

I suggest that you have an autonumber field with a format set to "02"000. All the format does is display the data to an Access user in that format. The field does not contain 02001, it contains 1. If you wish to recreate the format, you will have to do so in your application. Updating the autonumber to n will show as n in ADO and ODBC, but as 0200n in various places in Access - a format is not even relevant to queries in Access. I do not believe a format in a table is a good idea.

流星番茄 2025-01-09 23:26:17

您只能访问“02”吗?您编写的查询忽略了“02”,因此看起来您需要对这条信息进行单个查询。
我不是 vb 或 access 方面的专家,但看起来你可以使用一个快速的解决方案:你写道,你的密钥的形式为“02”000。我会单独取出每个数字,检查位数,将其转换为字符串并填充所有缺少的前导零,因为您知道最大位数。

参考总体评论显示的内容:
动态填充前导零并按名称引用表,以通过 if 子句决定您的房间 ID 是否以 R01 或 R02 开头。

Can you access to the "02" only? You wrote your query ignores "02", so it looks you need to have a single query for this piece of information.
I'm no expert in vb or access, but it looks like you can use a quick'n'dirty solution: You wrote, your keys have the form "02"000. I would take out each number by itself, check the number of digits, convert it to string and fill all leading zeros that are missing, because you know the maximum number of digits.

Referring to what overall comments show:
Filling dynamically leading zeros and referring to your table by name to decide by if-clause if your room-ID starts with R01 or R02.

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