问题
My SQL query is as follows:
SELECT * FROM Suppliers
WHERE SupplierName
LIKE 's%';
When I submit this query on W3 School's TryIt Editor (v1.2) (http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_like), it returns a number of records where the SupplierName begins with the letter 'S', as expected.
However, when I run this query on my own database in Access 2013, it doesn't return any records, even though my table name and field name are identical to W3's sample.
Queries not using 'LIKE' seem to work ok, for example:
SELECT * FROM Suppliers
WHERE SupplierName="Part Supplier, Inc.";
returns the appropriate record(s). It is only when 'LIKE' is used that Access returns no records at all.
My question is, is there any reason why LIKE queries don't return any records? The back-end data source is a Microsoft JET database (this is a relatively small database - no need for full SQL Server), but I don't think this should make a difference. Access doesn't complain about syntax or throw an error when I execute the query.
回答1:
From http://technet.microsoft.com/en-us/library/cc966377.aspx :
Microsoft Jet uses partial match (or "wildcard") characters with the Like operator that are different from those used in most SQL dialects. The asterisk (*) character matches zero or more characters and is equivalent to the percent (%) character in ANSI SQL. The other Microsoft Jet partial match characters are the question mark (?), which matches any character in a single field, and the number sign (#), which matches any digit in a single field.
The query should be modified like so:
SELECT * FROM Suppliers WHERE SupplierName LIKE 's*';
来源:https://stackoverflow.com/questions/19051037/why-is-my-like-query-not-returning-any-records-in-microsoft-access-2013-only