MS Access query: why does LIKE behave differently when being called from VB6 app?

后端 未结 6 1369
春和景丽
春和景丽 2021-01-06 23:32

I don\'t do a lot of coding with VB6, but I\'m updating an existing app now and just encountered a snag.

I figured out the problem. In VB6, queries must use the

相关标签:
6条回答
  • 2021-01-07 00:03

    Yes, you can get away with ALIKE in a Jet 4.0 OLE DB inquiry (i.e. from VB6 using ADO):

    JeTTY version 0.5.68
    >open booksale.mdb;
    #Opened database booksale.mdb (Jet3X "97")
    >select * from authors where author like "ba*";
    #No rows to display
    >select * from authors where author like "ba%";
                   Page 1 of 1
    Au_ID Author     Year Born
    ───── ────────── ─────────
    10    Bard, Dick 1941
    >select * from authors where author alike "ba%";
                   Page 1 of 1
    Au_ID Author     Year Born
    ───── ────────── ─────────
    10    Bard, Dick 1941
    >
    

    Of course you gain compatibility with Access but then lose ANSI SQL-92 compatibility for later upsizing to SQL Server, etc. and ultimately make more work for yourself.

    0 讨论(0)
  • 2021-01-07 00:04

    Access will use a subset of ANSI-89 wildcards by default, VB6, connecting through ADO will use ANSI-92.

    Operator Comparison

    Changing the mode Access uses

    0 讨论(0)
  • 2021-01-07 00:11

    I don't know if this applies to VB6, but within Access, you can use

    ALIKE '%something%'
    

    and the % characters will be treated as wildcards regardless of whether you're using VBA with DAO or ADO, or creating a query in the query editor.

    0 讨论(0)
  • 2021-01-07 00:14

    I've never seen the asterisk character used as a wildcard for a like statement (just everywhere else) -- generally speaking the percentage sign is what you would need to use.

    0 讨论(0)
  • 2021-01-07 00:21

    Yeah, that's normal.

    I think its the difference between DAO (what Access uses internally), and ADO (what VB6 uses to talk to Access).

    0 讨论(0)
  • 2021-01-07 00:23

    Access used to have its own incompatible version of SQL, so I think it uses the * for legacy reasons.

    When you use VB6 you usually use ODBC and a more standardized SQL, so the more common wildcards apply. Remember that VB6 doesn't care which DB you use, so if you used something else (e.g., SQL server) it would probably only understand the percentage signs.

    I am guessing that the Access-ODBC connector converts things for you.

    0 讨论(0)
提交回复
热议问题