Leading the way in Microsoft Office Development
 Home|Excel|Word|PowerPoint|Consultancy|Feedback|Contact 
 Microsoft Excel > Functions > External > SQL.REQUEST

 

SQL.REQUEST(connection_string, output_ref, driver_prompt, query_text, col_names_logical)

 
 Returns the results from a query executed against an external data source.

 connection_stringThe data source name, user id and password required by the driver.
 output_refThis is only relevant when you are not calling this function from a worksheet.
 driver_promptThe option for whether the driver prompt dialog box is displayed:
1 = dialog is always displayed
2 = dialog is only displayed when there is insufficient information (options are available)
3 = dialog is only displayed when there is insufficient information (options are not available)
4 = dialog is not displayed and an error is returned if unsuccessful
 query_textThe SQL statement you want to execute.
 col_names_logicalTrue or False to specify if column names are returned as part of the result.

 REMARKS
 
  • This function is only available if you have the Excel ODBC Add-in (XLODBC.xla) installed.
     
  • This add-in was installed by default with Excel 2000 but is no longer available as a built-in add-in.
     
  • Using this old Excel 7.0 add-in is not recommended as the ADO (ActiveX Data Object) library has since become the preferred method for connecting to external data sources.
     
  • If you are using a more recent version of Excel this add-in can be downloaded from the Microsoft website.
     
  • This add-in will be installed in the following folder: C:\Program Files\Microsoft Office\Office10\Library\Msquery\
     
  • The "connection_string" must be in the exact format for that particular driver.
     
  • The "connection_string" for dBase might be - DSN=Nwind;PWD=password.
     
  • The "connection_string" for SQL Server might be - DSN=ServerName;Database=People;UID=name;PWD=password.
     
  • The "connection_string" for Oracle might be - DNS=OracleDataSource;DBQ=Name;UID=name;PWD=password.
     
  • The "connection_string" must always contain the DNS (Data Source Name).
     
  • The "connection_string" can be entered as an array.
     
  • If the "connection_string" is longer than 250 characters you must enter it as an array.
     
  • If the "connection_string" is not valid and a connection cannot be made, then #N/A! is returned.
     
  • If "driver_prompt" is left blank, then 2 is used.
     
  • The "query_text" can be made up of cell references.
     
  • If "query_text" is longer than 255 characters then split the query into a group of vertical cells and pass in the cell range.
     
  • If "query_text" is invalid SQL or cannot be executed, then #N/A! is returned.
     
  • If "col_names_logical" is left blank, then False is used.
     
  • If this function is successful it will either return the result as an array or the number of rows affected.
     
  • For more examples please refer to the this Knowledge Base Article (124218).

     EXAMPLES
     
     A
    1SQL.REQUEST("DSN=Nwind;DBQ=C:\Temp\MsQuery;FIL=dBASE4", A1, 2, "SELECT Customer_ID FROM Orders WHERE OrderNo > 200", True)
    2SQL.REQUEST("DSN=MS Access Database;DBQ=C:\Personal\Databases\NorthWind\Nwind.mdb",,,"SELECT City FROM Customers WHERE (CustomerID='AROUT')")
     

     Functions - S | Index - S | Office Online 

     Copyright © 2004-2007 Better Solutions Limited. All Rights Reserved.Top