Fix Access Syntax Errors with SQL Server Stored Procedures
Question details
The user needs to run a SQL Server stored procedure from Microsoft Access without SQL syntax or conversion errors.

- Product
- Microsoft Access and SQL Server
- Device & OS
- not provided
- Scenario
- An Access database needs to use results from a SQL Server procedure containing T-SQL constructs and UNION queries.
- Observed behavior
- Access reports syntax or conversion errors when SQL Server T-SQL is used in an Access query.
Confirm that you can connect to the SQL Server database and have permission to execute the stored procedure. Have the procedure name, required parameters, and an ODBC data source name (DSN) ready.
Call the stored procedure through an Access pass-through query
Use a pass-through query to send T-SQL directly to SQL Server instead of having Access interpret it.
In SQL Server Management Studio, connect to the database and execute the procedure with valid parameters, for example: EXEC dbo.MyWorkQuery '2018-05-15', '2018-05-16'.
In Access, open the ACCDB file and select Create > Query Design. Close the table-selection dialog, then choose Pass-Through on the query design ribbon.
Open the query's Property Sheet and set ODBC Connect Str to a valid connection string using your SQL Server DSN and authentication method. Set Returns Records to Yes if the procedure returns a result set.
In the query's SQL view, enter the tested EXEC statement, then select Run. Save the query and use it as a record source for an Access report or from VBA.

Check UNION branches and data types in SQL Server
Use this check if the procedure still fails when tested directly in SQL Server.
Work with Office documents in WPS Office
WPS Office is a free, lightweight alternative for working with documents, spreadsheets, and presentations. Its familiar interface and support for common Microsoft Office formats make it easy to move existing files into your workflow. It does not fix Access queries or replace the SQL Server pass-through connection.

Frequently Asked Questions
Why does T-SQL fail in a regular Access query?
Access uses the ACE SQL dialect, which differs from SQL Server T-SQL. Create a pass-through query to send SQL Server-specific syntax directly to the server.
How do I connect an Access pass-through query to SQL Server?
Open the pass-through query's Property Sheet and enter a valid SQL Server ODBC connection string in ODBC Connect Str. The connection can use a configured DSN.
What should I check if a UNION query returns an error?
Run each SELECT separately in SQL Server Management Studio. Each branch must return the same number of columns, in matching order, with compatible data types.
Can an Access report use a stored procedure's results?
Yes. If the procedure returns a suitable result set, set the pass-through query's Returns Records property to Yes, save the query, and select it as the report's record source.




