SQL.RETRIEVE macro

Retrieves all or part of the results from a previously executed query. The connection used must have already been established using the macro function SQL.OPEN. Also, a query must already have been executed using SQL.EXEC.QUERY and results must be pending.

If this function is not available, you must install the Microsoft ODBC add-in (XLODBC.XLA).

Syntax

SQL.RETRIEVE(connection_num, destination_ref, max_columns, max_rows, col_names_logical, row_nums_logical, named_rng_logical, fetch_first_logical)

Connection_num    is the unique connection ID for a data source. The data source specified must have pending query results. Pending query results are generated by a call to SQL.EXEC.QUERY on the same connection.

 

Destination_ref    specifies where the results should be placed. It is either a reference to a single cell or it is omitted.

 

Max_columns    is the maximum number of columns to be retrieved. It is only used when destination_ref is not omitted.

 

Max_rows    is the maximum number of rows to be returned.

 

Col_names_logical    is a logical value which, if TRUE, causes the column names to be returned as the first row of results. It FALSE or omitted, the column names will not be returned.

Row_nums_logical    is used only when destination_ref is included. If row_nums_logical is TRUE then the first column in the result set will contain row numbers. If FALSE then row numbers will not be returned. This column of row numbers will not have a column name and the column heading will be left blank. Row numbers can also be retrieved by binding column number 0 with SQL.BIND.

Named_rng_logical    is a logical value which, if TRUE, sets each column of results to be declared as a named range on the worksheet. The name of the each range will be the result column name. The named range will only include the rows that were fetched with this SQL.RETRIEVE function call. If FALSE, the results will not be declared as a named range.

Fetch_first_logical    is a logical value that allows you to request results from the beginning of the result set.

 

Remarks

Example

SQL.RETRIEVE(conn1,sheet1!C1,1) stores data obtained from the data source conn1 on Sheet1 from left to right in cell C1, using only column 1.

Related Functions

SQL.OPEN   Establishes a connection with a data source

SQL.EXEC.QUERY   Sends a query to a data source

SQL.BIND   Specifies storage for a result column

SQL.RETRIEVE.TO.FILE   Retrieves query results and places them in a file

SQL.GET.SCHEMA   Gets information about a connected data source.

SQL.CLOSE   Close a data source connection

SQL.ERROR   Returns detailed error information

Return to index