LIKE SQL statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Woof-Woof

    LIKE SQL statement

    I have tried every combintion I can think of to get a VB5 recordset
    SQL query using the LIKE keyword to work recognizing the '*' wildcard
    character, but with no success. Why doesn't the LIKE keyword work with
    VB5 using ADO or DAO?

    Dim T$

    T$ = App.Path & "\MyAccess2000D B.mdb"
    T$ = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & T$
    ConnectStr = T$

    With myConnect
    On Error Resume Next
    .ConnectionStri ng = ConnectStr
    .ConnectionTime out = 10
    .Open
    On Error GoTo 0
    End With

    Set CorpRS = New ADODB.Recordset
    CorpRS.ActiveCo nnection = myConnect
    CorpRS.CursorTy pe = adOpenDynamic
    CorpRS.LockType = adLockOptimisti c

    field$ = "Symbol"
    term$ = "IBM"

    'this works but I can't get wildcards to work
    sql$ = "Select * from Corporations WHERE " & field$ & " Like '" &
    term$ & "'"

    CorpRS.Open sql$

    I cannot equate term$ to anything and get the query to recognize
    wildcards.
    For example, if term$ = "*M*", I want the query to return MSFT, MMM,
    MCD, etc.

    Any ideas?

    Thank you.



    ---
    Allen



  • Woof-Woof

    #2
    Re: LIKE SQL statement

    Found the answer:

    In ADO, the wild card character is "%", not "*".


    Sheeesh!



    ---
    Allen


    "Woof-Woof" <otie_nospam@co x.net> wrote in message
    news:ktsFc.3532 6$6r1.33788@fed 1read06...[color=blue]
    > I have tried every combintion I can think of to get a VB5 recordset
    > SQL query using the LIKE keyword to work recognizing the '*'[/color]
    wildcard[color=blue]
    > character, but with no success. Why doesn't the LIKE keyword work[/color]
    with[color=blue]
    > VB5 using ADO or DAO?
    >
    > Dim T$
    >
    > T$ = App.Path & "\MyAccess2000D B.mdb"
    > T$ = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & T$
    > ConnectStr = T$
    >
    > With myConnect
    > On Error Resume Next
    > .ConnectionStri ng = ConnectStr
    > .ConnectionTime out = 10
    > .Open
    > On Error GoTo 0
    > End With
    >
    > Set CorpRS = New ADODB.Recordset
    > CorpRS.ActiveCo nnection = myConnect
    > CorpRS.CursorTy pe = adOpenDynamic
    > CorpRS.LockType = adLockOptimisti c
    >
    > field$ = "Symbol"
    > term$ = "IBM"
    >
    > 'this works but I can't get wildcards to work
    > sql$ = "Select * from Corporations WHERE " & field$ & " Like '"[/color]
    &[color=blue]
    > term$ & "'"
    >
    > CorpRS.Open sql$
    >
    > I cannot equate term$ to anything and get the query to recognize
    > wildcards.
    > For example, if term$ = "*M*", I want the query to return MSFT, MMM,
    > MCD, etc.
    >
    > Any ideas?
    >
    > Thank you.
    >
    >
    >
    > ---
    > Allen
    >
    >
    >[/color]


    Comment

    Working...