在表格的一个短文本列中存储了这样的数据" any_text_N"其中N是每行特定的数字
我需要用N + 1替换N.
任何人都可以提供查询吗?
答案 0 :(得分:1)
假设(1)数字始终是最右边的字符,(2)数字前面有下划线,您可以创建一个函数来解析数字并返回递增的值(见下文)。
然后测试它,创建一个如下的查询(确保你首先测试!!!):
SELECT Table2.MyText, resetnbr([MyText]) AS NewVal
FROM Table2
WHERE (((Table2.MyText) Is Not Null));
然后更新您的数据:
UPDATE Table2 SET Table2.MyText= resetnbr([MyText])
WHERE (((Table2.MyText) Is Not Null));
Public Function ResetNbr(strIn As String) As String
'Assumes: (1) Number in rightmost position of string; (2) underscore preceeds number
Dim iLen As Integer
Dim i As Integer
Dim sNbr As String
If strIn = "" Then
ResetNbr = strIn
Exit Function
End If
iLen = Len(strIn)
For i = iLen To 1 Step -1
If Mid(strIn, i, 1) = "_" Then
Exit For
End If
Next i
If i > 1 Then
sNbr = Mid(strIn, i + 1, 99)
sNbr = sNbr + 1
ResetNbr = left(strIn, i) & sNbr
Else
' No underscore found!
ResetNbr = strIn
End If
End Function