Query files are text files that contain data source (data source: A stored set of "source" information used to connect to a database. A data source can include the name and location of the database server, the name of the database driver, and information that the database needs when you log on.) information, including the name of the server where the data is located and the connection information you provide when you create a data source. Query files make it possible for you to share queries with other users.
Opening either an Office database connection ( .odc) file or database query (.dqy) file runs the query and displays a worksheet containing the retrieved data. Opening a .odc or OLAP (OLAP: A database technology that has been optimized for querying and reporting, instead of processing transactions. OLAP data is organized hierarchically and stored in cubes instead of tables.) query (.oqy) query file connects you to the OLAP database or cube and displays a worksheet with a blank PivotTable report for the OLAP data. After you open a query file, you can save an Excel workbook file that contains the retrieved external data (external data: Data that is stored outside of Excel. Examples include databases created in Access, dBASE, SQL Server, or on a Web server.). However, you can't use the Save command on the Excel File menu to save in the .dqy or .oqy query file formats.
Creating query files
Creating .odc query files You can create .odc files by connecting to external data through the Select Data Source dialog box or by using the Data Connection Wizard to connect to new data sources. If you need only one table and you don't need to filter data, .odc files are the recommended method for connecting to and sharing data in relational databases, text files, or Excel lists.
Creating .dqy query files You can use Microsoft Query to save .dqy files that contain queries for data in relational databases, text files, or Excel lists. When you open these files in Query, you can view the data in the query and select different data for the query to retrieve. You can save a .dqy file for any query that you create either by using the Query Wizard or directly in Query.
Creating .oqy query files You can save .oqy files to connect to data in an OLAP database, either on a server or in an offline cube file (offline cube file: A file you create on your hard disk or a network share to store OLAP source data for a PivotTable or PivotChart report. Offline cube files allow you to keep working when you are not connected to the OLAP server.) (.cub). When you use Query to create a data source for an OLAP database or cube, an .oqy file is created automatically. Because OLAP databases aren't organized in records or tables, you can't create queries or .dqy files to access these databases.
You can also use the OLAP Cube Wizard in Query to save an .oqy file that connects to a cube file or defines a cube (cube: An OLAP data structure. A cube contains dimensions, like Country/Region/City, and data fields, like Sales Amount. Dimensions organize types of data into hierarchies with levels of detail, and data fields measure quantities.) that is created from queried data. This type of .oqy file can include both information that defines what is in the cube and connection information for the relational database. When you open this type of .oqy file in Query, the OLAP Cube Wizard runs so that you can change the cube definition.
Using other query file formats
Using . rqy query files Excel can open query files in .rqy format to support OLE DB data source drivers that will use this format. For more information, see the documentation for your driver.
Using . qry query files Query can open and save query files in .qry format for use with earlier versions of Query that cannot open .dqy files. If you have a query file in .qry format that you want to use in Excel, open the file in Query, and then save it as a .dqy file. For information about saving .dqy files, see Microsoft Query Help.
Using .iqy Web query files Excel can open .iqy Web query files to retrieve data from the Web. You don't need to install Query to create and open .iqy files in Excel.
Sharing data
Sharing query files You can share query files with other people to give them the same access you have to an external database. Other users don't have to set up a data source to open the query file, but they do have to install the ODBC driver (Open Database Connectivity (ODBC) driver: A program file used to connect to a particular database. Each database program, such as Access or dBASE, or database management system, such as SQL Server, requires a different driver.) or data source driver (data source driver: A program file used to connect to a specific database. Each database program or management system requires a different driver.) required to access the external data.
To prevent unauthorized users from accessing the data source, you should save your password when you create the data source for the query file. The password will be stored in the query file and anyone who opens this file in Excel must enter the password to access the database.
Reusing and sharing queries Excel can open .odc and .dqy files directly, which allows you or others to create additional external data ranges from the same query. In Query Wizard and Query, you can save a .dqy query file that you can modify, reuse, and share.
If you want to share a summary or report that is based on external data, you can give other users a workbook that contains an external data range, or you can create a report template. A report template (report template: An Excel template (.xlt file) that includes one or more queries or PivotTable reports that are based on external data. When you save a report template, Excel saves the query definition but doesn't store the queried data in the template.) lets you save the summary or report without saving the external data so that the file is smaller. The external data is retrieved when a user opens the report template.
Formatting and changing queries
Changing the format and layout You can change the format and layout of the external data range.
Changing a report template After you create a report template, you can make changes to the template as needed.