Article ID: 173097 - Last Review: January 20, 2007 - Revision: 3.1 ACC: Query with Time Criteria Returns No Records from Microsoft SQL ServerThis article was previously published under Q173097 Moderate: Requires basic macro, coding, and interoperability skills.
On This PageSYMPTOMS
When you run a query based on a linked (attached) Microsoft SQL Server
table that contains a Date/Time field, and the criteria for the Date/Time
field contains a literal time value, Microsoft Access returns an empty
result set.
CAUSE
When a linked SQL Server table contains a field with a data type of
Date/Time, and you insert a time value such as 12:35:00 P.M. into the table, the following calls are made by the SQL Server ODBC driver:
SQLPrepare :
INSERT INTO "dbo"."tblTimeTest" VALUES (?)
SQLBindParam:
12:35:00
1899-12-30 12:35:00.00
SQLExecDirect:
SELECT "dbo"."tblTimeTest"."TimeTest" FROM "dbo"."tblTimeTest" WHERE _
("TimeField" = {t '12:35:00'})
RESOLUTION
Use either of the following methods to resolve this problem.
Method 1Create a parameter query in Microsoft Access. You can use the query-by-form technique and specify a control on a form as a parameter; you can also define the parameter in the query itself and specify its data type as Date/Time. For example:Field: TimeField Criteria: [Enter Time] 95931
(http://support.microsoft.com/kb/95931/EN-US/
)
ACC: How to use the Query-by-Form (QBF) Technique
Method 2Create the following expression in the query to extract the time portion of the field:Expr1: CVDate(Format([<Name of Time Field>],"hh:nn:ss AM/PM")) You can then enter the literal time value enclosed in number signs (#) on the Criteria row of this expression. STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. MORE INFORMATIONSteps to Reproduce Behavior
REFERENCES
For more information about specifying the data type of query parameters,
search the Help Index for "data types, parameter queries."
APPLIES TO
| Article Translations
|


Back to the top
