More Information
A SEARCH on an Exchange calendar folder with a constraint of a begin and an end date is called an expansion query. This means, that all recurring appointments are expanded, and each instance is returned in the query. (See Searching Calendar Folders with WebDAV on MSDN for more information. The article specifically targets the WebDAV protocol, but the issue explained here applies to the ExOleDB provider as well).
An example of such a query is displayed below.
If you run this query and use values for the start and end properties where the difference between start and end is greater than 732 days, you get the following error:
Error while processing WHERE clause in the SQL statement.
Example
An example of such an expansion query might look like this:
1 SEARCH /exchange/~username/calendar/ HTTP/1.1
2 Host: www.example.com
3 Content-Type: text/xml
4
5 <?xmlversion="1.0"?>
6 <g:searchrequestxmlns:g="DAV:">
7 <g:sql>
8 Select "urn:schemas:calendar:location", "urn:schemas:httpmail:subject",
9 "urn:schemas:calendar:dtstart", "urn:schemas:calendar:dtend",
10 "urn:schemas:calendar:busystatus", "urn:schemas:calendar:instancetype"
11 FROM Scope('SHALLOW TRAVERSAL OF ""') WHERE
12 "DAV:contentclass" = 'urn:content-classes:appointment'
13 AND "urn:schemas:calendar:dtstart" > CAST("2005-01-01T00:00:00Z" AS 'dateTime.tz')
14 AND "urn:schemas:calendar:dtend" < CAST("2006-01-01T00:00:00Z" AS 'dateTime.tz')
15 ORDER BY "urn:schemas:calendar:dtstart" ASC
16 </g:sql>
17 </g:searchrequest>
Workaround
To work around this problem, do your search in multiple steps, with a time span of two years or less.
Status
This is a known limitation in the Exchange Server: Expansion queries are limited to a time span of two leap years.