强制短文本字段始终为 X 个字符
Force Short TextField To Always Be X Characters
我试图在查询中使用 IIF()
语句将短文本字段更新为始终为 4 个字符。这是我的语法,但是
SELECT DISTINCT IIf(Len([User ID] = 1), "000" & [User ID], IIf(Len([User ID] = 2), "00" & [User ID], IIf(Len([User ID] = 3), "0" & [User ID], [User ID]))) AS ST
FROM _TestData;
然而,无论长度如何,它似乎都在向数据附加 0?
如果 [User ID]
是数字,试试这个:
SELECT DISTINCT Format([User ID], "0000") AS ST
FROM _TestData;
更新
错过了该字段是短文本。在这种情况下
SELECT DISTINCT Format(CLng(Nz([User ID],0)), "0000") AS ST
FROM _TestData;
可以这么简单:
SELECT DISTINCT Right("000" & [User ID], 4) AS ST
FROM TestData;
我试图在查询中使用 IIF()
语句将短文本字段更新为始终为 4 个字符。这是我的语法,但是
SELECT DISTINCT IIf(Len([User ID] = 1), "000" & [User ID], IIf(Len([User ID] = 2), "00" & [User ID], IIf(Len([User ID] = 3), "0" & [User ID], [User ID]))) AS ST
FROM _TestData;
然而,无论长度如何,它似乎都在向数据附加 0?
如果 [User ID]
是数字,试试这个:
SELECT DISTINCT Format([User ID], "0000") AS ST
FROM _TestData;
更新
错过了该字段是短文本。在这种情况下
SELECT DISTINCT Format(CLng(Nz([User ID],0)), "0000") AS ST
FROM _TestData;
可以这么简单:
SELECT DISTINCT Right("000" & [User ID], 4) AS ST
FROM TestData;