Fix Microsoft Query Invalid Cast Error with Date Parameters
Question details
Users encounter an 'Invalid character value for cast specification' error in Microsoft Query when entering date parameters in criteria expressions.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Filtering data sources using date parameters like 'between [a] and [b]' within Microsoft Query.
- Observed behavior
- The query fails to execute and displays an 'Invalid character value for cast specification' error due to a mismatch in parameter formatting and the driver's expected data type.
Identify the specific ODBC driver you are using and confirm the exact date format (e.g., YYYY-MM-DD) required by your underlying database before modifying your query parameters.
Verify Source Field Types and Parameter Definitions
Check how Microsoft Query passes parameter values to your specific database driver and adjust the date format to resolve the type casting issue.
This error generally occurs when the data source driver receives a text string from the parameter prompt that it cannot convert into a valid Date or DateTime data type.
In Microsoft Query, navigate to the specific criteria row where your date parameter (e.g., between [start_date] and [end_date]) is located.
Verify that the underlying database column being filtered is strictly defined as a Date or DateTime field, not a general text field.
When prompted to enter the parameter value, manually input the date using the strict format expected by your ODBC driver, such as 'YYYY-MM-DD' instead of 'MM/DD/YY'.
Re-run the query to confirm if the ODBC driver now successfully accepts the parameter without throwing the cast specification error.

Test Query with Hardcoded Dates
Isolate the issue by replacing dynamic parameters with static date strings to confirm if driver syntax or parameter mapping is the root cause.
Switch to WPS Office for Seamless Data Management
If you frequently encounter complex driver errors in Microsoft Office, consider trying WPS Office. It provides a lightweight, highly compatible alternative with intuitive data handling and reliable import/export tools.
- 1. Download WPS Office: Visit the official WPS website to download the free, lightweight installation package.
- 2. Install and Launch: Run the installer and open WPS Spreadsheet to access reliable data analysis features.
- 3. Import External Data: Use the integrated data import tools to seamlessly connect to and manage your data sources without complex driver configuration.

Frequently Asked Questions
Why do I get an 'Invalid character value for cast specification' error?
This error occurs when the ODBC driver or data source cannot convert the parameter value you entered into the expected data type. For example, it happens when trying to parse a text string that is not recognized as a valid Date format.
How should I format date parameters in Microsoft Query?
The required format heavily depends on your specific database driver. Common formats include 'YYYY-MM-DD' or 'MM/DD/YYYY'. Always check your specific ODBC driver documentation to ensure you are entering the correct syntax.
Can I use dynamic parameters in an SQL pass-through query?
No, Microsoft Query does not support graphical dynamic parameters (like prompts using brackets [Enter Date]) in direct SQL pass-through queries. You must use standard query types or visual criteria grids to prompt for parameter inputs.




