• SQL string ASP – Access LIKE usage

    Home » Forums » Developers, developers, developers » Web design and development » SQL string ASP – Access LIKE usage

    Author
    Topic
    #361961

    **Edited by KT to include link**
    I am trying to build a SELECT statement in VBScript that pulls data from an Access db on my webserver. things are fine with I string together many AND statements but, of course, that focuses my seraches too quickly. One of the fields I am querying on needs to support the LIKE statement and pull data from any column that *contains* a particular county (many records have several counties listed). When I implement LIKE it just pulls records that MATCH the county, leaving out those records with multiple counties.

    In Access, the SQL view of the query I need looks like this:

    SELECT CRCG_Contacts.County
    FROM CRCG_Contacts
    WHERE (((CRCG_Contacts.County) Like “*falls*”));

    [In this case, ‘Falls’ is a particular county]

    As you may notice, the query picks up lines with multiple counties listed with the wildcard character for Access, the asterisk [*] placed on both sides. Now, on the .asp page… I placed the same type of query as this string:

    SQLstring = “SELECT * FROM CRCG_Contacts WHERE County LIKE ‘”&*County*&”‘;”

    And that nets me this error:

    Microsoft VBScript compilation (0x800A03EA)
    Syntax error
    /crcg2/Locals_Search_Results.asp, line 169, column 62
    SQLstring = “SELECT * FROM CRCG_Contacts WHERE County LIKE ‘ ” & * County * & ” ‘ ; ”
    Microsoft VBScript compilation (0x800A03EA)
    Syntax error
    /crcg2/Locals_Search_Results.asp, line 169, column 62
    SQLstring = “SELECT * FROM CRCG_Contacts WHERE County LIKE ‘”&*County*&”‘;”

    I’ve tried many varients and even used other wildcard characters such as %, etc. but it seems to me that if I am querying Access the Access wildcard is what is needed and, since the coding is blocked out by double quotes the silly VB Compiler shouldn’t be griping, darnit! bash i tried ‘On Error Resume Next’ but that didn’t help much.

    So, is there some special wildcard character to syntax that I am missing? sure seems so.

    For the record, this is an ASP form that is, for test purposes, posting to itself. If you need more of the code, let me know.

    You can get a feel for what I am up to in a previous posting called ‘ASP/SQL – this is probably easy! ‘ in this forum.

    Thanks!

    Viewing 0 reply threads
    Author
    Replies
    • #548736

      You put a literal character outside the “” marks. Try putting it inside:
      LIKE ‘%” & County & “%’;”
      (I have had success with % in ASP; I think if * worked I wouldn’t have tried %)

    Viewing 0 reply threads
    Reply To: SQL string ASP – Access LIKE usage

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: