Mentioned
In
|
 |
 |
 |
 |
Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms
of Use |
Trademarks
Article ID: 303968 - Last Review: April 6, 2007 - Revision: 5.1 How to create an SQL pass-through query in AccessThis article was previously published under Q303968 Moderate: Requires basic macro, coding, and interoperability
skills.
This article applies only to a Microsoft Access database (.mdb or .accdb).
SUMMARY SQL pass-through queries are used to send commands directly
to an ODBC database server. By using an SQL pass-through query, you work
directly with the server tables instead of having the Microsoft Jet database
engine process the data. MORE INFORMATION To create an SQL pass-through query, you must first create
a system data source name (DSN,) and then you can create the SQL pass-through
query. Creating the System DSN on a Microsoft Windows 2000-Based or a Windows 2003-Based Computer- Click Start, point to Settings, and then Click Control Panel.
- In Control Panel, double-click Administrative Tools.
- Double-click Data Sources (ODBC).
- In the ODBC Data Source Administrator dialog box, click the System DSN tab.
- Click Add.
- Select the appropriate driver.
- Click Finish, and then provide other required information for the selected
driver.
Creating the System DSN on a Microsoft Windows Millennium Edition-Based Computer- Click Start, point to Settings, and then Click Control Panel.
- In Control Panel, double-click Data Sources (ODBC 32-bit).
- Click the System DSN tab.
- Click Add.
- Select the appropriate driver, and then click OK.
- Click Finish, and then provide other required information for the selected
driver.
Creating the SQL Pass-Through QueryAccess 2002 or Access 2003- In the Database window, click Queries under Objects, and then click New.
- In the New Query dialog box, click Design View, and then click OK.
- Click Close in the Show Table dialog box without adding any tables or queries.
- On the Query menu, point to SQL Specific, and then click Pass-Through.
- On the toolbar, click Properties to display the property sheet for the query.
- In the query property sheet, place the mouse pointer in the
ODBC Connect Str property, and then, click the Build (...) button.
With the ODBC Connect Str property, you specify information about the database to which you
want to connect. You can type the connection information, or click Build, and then enter information about the server to which you are
connecting. - When you are prompted to save the password in the
connection string, click Yes if you want the password and logon name to be stored in the
connection string information.
- If the query is not the type that returns records, set the ReturnsRecords property to No.
- In the SQL Pass-Through Query window, type your
pass-through query. For example, the following pass-through query uses the
Microsoft SQL Server TOP operator in the SELECT statement to return only the
first 25 orders in the Orders table from the sample Northwind database:
SELECT TOP 25 orderid from orders
- To run the query, click Run on the toolbar. (For a SQL pass-through query that returns
records, click View on the toolbar.)
- If necessary, Microsoft Access prompts you for information
about your server database.
Access 2007- On the Create tab, click Query Design in the Other group.
- Click Close in the Show Table dialog box without adding any tables or queries.
- On the Design tab, click Pass-Through in the Query Type workgroup.
- Click Property Sheet in the Show/Hide workgroup to display the property sheet for the query.
- In the query property sheet, place the mouse pointer in the
ODBC Connect Str property, and then, click the Build (...) button.
With the ODBC Connect Str property, you specify information about the database to which you
want to connect. You can type the connection information, or click Build, and then enter information about the server to which you are
connecting. - When you are prompted to save the password in the
connection string, click Yes if you want the password and logon name to be stored in the
connection string information.
- If the query is not the type that returns records, set the ReturnsRecords property to No.
- In the SQL Pass-Through Query window, type your
pass-through query. For example, the following pass-through query uses the
Microsoft SQL Server TOP operator in the SELECT statement to return only the
first 25 orders in the Orders table from the sample Northwind database:
SELECT TOP 25 orderid from orders
- To run the query, click Run in the Results group on the Design tab. For a SQL pass-through query that returns records, click Datasheet view on the status bar.
- If necessary, Microsoft Access prompts you for information
about your server database.
REFERENCES For more information about pass-through queries, see the
"Create a pass-through query that sends commands to an SQL database" topic in
the "Create an SQL-specific query" section in Access Help. For more
information about creating DSNs, see the Help file for your operating system or
see the ODBC Help file.
APPLIES TO- Microsoft Office Access 2007
- Microsoft Office Access 2003
- Microsoft Access 2002 Standard Edition
| kbquery kbsqlprog kbhowto KB303968 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please
|
 |
 |
 |
 |
 |
 |
 |
| |