ACC2000: Using LIKE with Wildcards May Cause Unexpected ResultsID: Q199163
|
Moderate: Requires basic macro, coding, and interoperability skills.
In a Microsoft Access query, if you use the LIKE operator with a wildcard to search for dates, you may see unexpected results.
The Like function is used to compare two strings. It does not inspect the string for any type of date information.
Use the comparison operators <, >, <=, =>, <> or the BETWEEN clause when searching for dates. For example, when looking for dates in the month of May 97, use the following syntax:
Orders.OrderDate >= 5/1/1997 and Orders.OrderDate <=5/31/1997
SELECT Orders.CustomerID, Count(*) AS NumberOfOrders
FROM Orders
WHERE (((Orders.OrderDate) BETWEEN #5/1/97# AND #5/31/97#))
GROUP BY Orders.CustomerID
SELECT Orders.CustomerID, Count(*) AS NumberOfOrdersNOTE: The only difference from the SQL above is that the WHERE clause uses a wildcard.
FROM Orders
WHERE (((Orders.OrderDate) LIKE "5/*/97"))
GROUP BY Orders.CustomerID
SELECT Orders.CustomerID, Count(*) AS NumberOfOrders
FROM Orders
WHERE (((Orders.OrderDate) LIKE "5/*/1997"))
GROUP BY Orders.CustomerID
Additional query words: prb
Keywords : kbdta
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: May 13, 1999