Article ID: 101375
Article Last Modified on 1/26/2005
APPLIES TO
- Microsoft Access 1.0 Standard Edition
- Microsoft Access 1.1 Standard Edition
- Microsoft Access 2.0 Standard Edition
- Microsoft Access 95 Standard Edition
This article was previously published under Q101375
SUMMARY
Advanced: Requires expert coding, interoperability, and multiuser skills.
This article describes how to use the SQL IN clause to query an SQL Server table without linking (attaching) it.
MORE INFORMATION
You can use IN to query only one external database at a time.
The IN clause requires two arguments: database name and connect string. When you link SQL Server tables, you must specify an empty string for the database name. The connect string consists of the following items:
Data Source Name (DSN) The name of the SQL Server computer Database Name (DATABASE) The name of the SQL Server database Workstation ID (WSID) The name of the workstation that is making the connection (optional) User ID (UID) The login ID* Password (PWD) The user password* * This item is optional within the connect string. If it is not present, the system prompts the user with a dialog box to enter this information the first time the macro is executed each session.
The following is a sample connect string to SQL Server. Note that it starts with "ODBC," which tells the system that it uses the ODBC driver (as opposed to an installable ISAM driver).
ODBC;DSN=ServerName;Database=Pubs;WSID=Wrk1;USID=JaneDoe;PWD=ABC123
The following example assumes that the ODBC driver manager and SQL Server driver are installed, that a data source called "Corp" was set up using the ODBC driver manager, and that the table "authors" can be successfully linked from the database Pubs, using the Get External Data/Link Tables commands on the File menu (or Attach Table command on the File menu in versions 1.x and 2.0).
- Open the sample database Northwind.mdb (or NWIND.MDB in version 1.x and ,2.0)
- Create a new query. Do not select a table.
- On the View menu, click SQL.
- Enter the following SQL statement into the SQL window:
Select *
FROM authors
IN "" "ODBC;dsn=Corp;database=pubs;uid=<login name>;pwd=<password>";
- Close the SQL dialog box and close and save the query.
NOTE: If you return to the View SQL window after saving the query, Microsoft Access may place additional characters in the IN clause that you must remove to avoid a syntax error.
REFERENCES
For more information using Microsoft Access as a front end, search for "SQL," and then " SQL Databases" using the Microsoft Access for Windows 95 Help Index.
For more information about the IN clause, search for "IN (SQL)," and then "IN Clause (SQL)" using the Microsoft Access for Windows 95 Help Index.
Additional query words: attach remote data source
Keywords: kbhowto kbusage KB101375