我的一个查询语句是这样的。
“select * from Table where 条件 order by 编号”现在我想取出上面语句中的 "from Table where 条件"  哪位高手能教我一下。不胜感激!!!!!!!!!!!!!!!!!!!

解决方案 »

  1.   

    Dim a As String
    Dim StartPoint  As Integer
    Dim StrLen As Integer
    a = "select * from Table where 条件 order by 编号"
    StartPoint = InStr(1, a, "from")
    StrLen = InStr(1, a, "order") - StartPoint
    Debug.Print Mid(a, StartPoint, StrLen)
      

  2.   

    Dim XX As String, I As Integer
    XX = "select * from Table where 条件 order by 编号"
    I = InStr(XX, "order by")
    If I <> 0 Then
        XX = Trim(Mid(XX, 1, I - 1))
    End If
    MsgBox XX
      

  3.   

    dim lstrTmp as string
    dim str as string
    str=“select * from Table where 条件 order by 编号”
    lstrTmp=mid(str,instr(str,"from"))
    lstrTmp=left(lstrTmp,instr(str,"order")-2)
    注意:如果没有Order子句时,会出错;另外还要注意大小写。
      

  4.   

    Dim strTemp As String
        Dim i As Integer
        Dim j As Integer
        
        strTemp = "select * from Table where 条件 order by 编号"
        
        i = InStr(UCase(strTemp), UCase("from"))
        j = InStr(UCase(strTemp), UCase("order"))
        
        MsgBox Mid$(strTemp, i, j - i)
      

  5.   

    dim iPos as integer
    dim strSQL as string 
    strSQL="select * from Table where 条件 order by 编号"
    ipos=instr(1,strSQL,"from")
    字串=mid$(strsql,ipos+1)
      

  6.   

    '上面的程序都不是太理想,只要字串中先后有两个符合要求的子串,就应该获得答案,总不能让楼主所有的sql语句中都有“order”吧:Option ExplicitPrivate Sub Command1_Click()
        Dim s As String
        s = "select * from Table where 条件 order by 编号"
        Debug.Print findstr("from", "条件", s)
    End Sub
    Private Function findstr(ByVal word1 As String, ByVal word2 As String, ByVal finds As String) As String
        Dim i As Long, j As Long
        i = Len(word1)
        If i = 0 Then
            Exit Function
            findstr = ""
        ElseIf i > Len(finds) Then
            Exit Function
            findstr = ""
        End If
        j = Len(word2)
        If j = 0 Then
            Exit Function
            findstr = ""
        ElseIf j > Len(finds) Then
            Exit Function
            findstr = ""
        End If
        Dim num1 As Long, num2 As Long
        num1 = InStr(1, finds, word1)
        If num1 = 0 Then
            Exit Function
            findstr = ""
        End If
        num2 = InStr(num1, finds, word2)
        If num2 = 0 Then
            Exit Function
            findstr = ""
        End If
        Dim findlength As Long
        findlength = num2 - num1 + Len(word2)
        findstr = Mid(finds, num1, findlength)
        
    End Function