从一行中删除字母

时间:2015-11-24 17:07:46

标签: ms-access ms-access-2013

我正在使用GPS卡车跟踪数据库,我想删除某一列中的所有信件。或者,如果更容易推断所有数字并将它们放在自己的列中。左,右,中将不起作用,因为每个数字位置的数值会逐行变化。Screen Shot of DB 我不确定这在访问中是否可行,或者我是否必须通过python传递数据来执行我想要的操作。

3 个答案:

答案 0 :(得分:0)

尝试

select
to_timestamp(k_time/1000),
k_time,
k_123,
k_456,
SUM(789)  as 789,
SUM(111)  as 111,
SUM(aaa)  as aaa
FROM table
WHERE k_abc = 0
AND to_timestamp(k_time/1000) BETWEEN '2015-11-22'::DATE AND '2015-11-24'::DATE
AND k_xyz = 'test' AND k_456 = 'result'

GROUP BY k_time,k_123,k_456
ORDER BY k_time,k_123,k_456;

返回“abcdefg”中“c”的字符位置,如果不匹配则返回0。

使用vba以编程方式处理记录或直接使用查询但效率不高。 恩。 (逐步使其更清晰)

2015-11-23 00:00:00+00  1448236800000   K_456   k_xyz   0   4   84
2015-11-23 00:00:00+00  1448236800000   K_457   k_xyz   0   0   2
2015-11-23 00:00:00+00  1448236800000   K_458   k_xyz   0   15  263
2015-11-23 00:00:00+00  1448236800000   K_459   k_xyz   0   0   3
2015-11-23 00:00:00+00  1448236800000   K_460   k_xyz   0   1   191
2015-11-23 00:01:00+00  1448244000000   K_456   k_xyz   0   2   260
2015-11-23 00:01:00+00  1448244000000   K_457   k_xyz   0   1   63

将“found”替换为:

InStr( startPosition, "abcdefg", "c" )

这将切断左边的所有内容“On Duty,odo:”,“Driving,odo:”。

由于无法在查询中存储临时变量,只需使用几个InStr()来查找“odo:”并可能“Miles”然后再次使用它们来计算长度。对于少量记录,这将是好的,否则更好地使用VBA来提高效率。

答案 1 :(得分:0)

以下两种方法只返回数字 - 但您需要告诉我们您要解析哪个字段。

Option Compare Database
Option Explicit

Function Test_This()
Dim strIN   As String
    strIN = "On Duty, odo: 245678.9,"
    MsgBox "Loop Method:" & vbCrLf & "Input String: " & strIN & vbCrLf & "Output String: " & Method_Loop(strIN)
    MsgBox "Parse Method:" & vbCrLf & "Input String: " & strIN & vbCrLf & "Output String: " & Method_Parse(strIN)

End Function


Function Method_Parse(InValue As String) As String
Dim i   As Integer
Dim i2      As Integer
Dim iLen    As Integer
Dim strOut  As String
    iLen = Len(InValue)
    i2 = 0
    strOut = ""

    ' Assume delimiter is colon + space
    i = InStr(1, InValue, ": ")
    If i = 0 Then
        MsgBox "No starting delimiter (: ) for '" & InValue & "'", vbOKOnly, "No Start Delimiter"
        Method_Parse = ""
        Exit Function
    End If
    i2 = InStr(i, InValue, ",")
    If i2 = 0 Then
        MsgBox "No ending delimiter (,) for '" & InValue & "'", vbOKOnly, "No End Delimiter"
        Method_Parse = ""
        Exit Function
    End If
    strOut = Mid(InValue, i + 2, i2 - i - 2)
    Method_Parse = strOut
End Function

Function Method_Loop(InValue As String) As String
Dim i       As Integer
Dim i2      As Integer
Dim iLen    As Integer
Dim strOut  As String

    iLen = Len(InValue)
    i2 = 0
    strOut = ""
    For i = 1 To iLen
        ' If you can have a period that is not part of the number,
        ' and your number's can have decimal places, then modify the code
        ' to check if 'IsNumeric' for the prefeeding and following characters.
        If (IsNumeric(Mid(InValue, i, 1))) Or (Mid(InValue, i, 1) = ".") Then
            strOut = strOut & Mid(InValue, i, 1)
        End If
    Next i
    Method_Loop = strOut

End Function

答案 2 :(得分:0)

从该屏幕截图中可以看出:

X = InStr(0, Description, ":" ) 'Gets the position of the first semicolon
Y = InStr(X, Description, "," ) 'Gets the position of the following comma

然后你可以在Mid语句中使用这两个数字:

Z = Mid(Description, X + 1, Z - 1)

那应该给你里程表读数。

如果您需要其他数字,请继续使用该逻辑。