Microsoft KB Archive/70067

{| = Using DB.SQL.QUERY with Type 2 Requires Double Single Quotes =
 * width="100%"|

Last reviewed: November 3, 1994

Article ID: Q70067

SUMMARY
The command DB.SQL.QUERY, provided by the add-in QE.XLA, allows you to send SQL queries to Q+E. The query is executed by Q+E and the results are returned to Excel.

When sending a query that contains a text comparison criteria, it is necessary to place the criteria inside double single quotation marks. (for example, ``NC''). Without the double single quotation marks, the command will return #REF.

DB.SQL.QUERY(type,query,destination,filename,linked)
The first argument, &quot;type&quot;, is a number from 1 to 3 indicating the type of query to be executed.


 * Type 1 specifies that the previous query is to be executed.
 * Type 2 executes the text string specified by the argument &quot;query&quot;.
 * Type 3 executes a query contained in the file specified by &quot;filename&quot;.

If &quot;type&quot; is 2 and you use a WHERE clause to limit your extract to only records that match certain criteria in the form of text, you must enclose the text value in two sets of single quotation marks or two sets of double quotation marks. The following example:


 * Initiates a DDE channel with Q+E
 * Activates Sheet1 in Excel
 * Selects all records in ADDR.DBF where the state is equal to &quot;NC&quot;
 * Pastes those records into Sheet1, starting with the active cell

For this macro to work correctly, you must:
 * 1) In A3, change the path to the actual location of ADDR.DBF.
 * 2) Change A2 to indicate an open worksheet.
 * 3) The add-in QE.XLA must be loaded.
 * 4) The third line should all be entered into the same cell. It is split into two lines here for readability.
 * 5) Place two single quotation marks to the left of &quot;NC&quot; and two single quotation marks to the right, followed by a double quotation mark that matches the double quotation mark before &quot;select&quot;.
 * 6) You may also use two sets of double quotation marks instead of two sets of single quotation marks.

Example
A1 =INITIATE(&quot;qe&quot;,&quot;system&quot;) A2 =ACTIVATE(&quot;sheet1&quot;) A3 =DB.SQL.QUERY(2,&quot;select * from dBASEfile | d:\excel\xl3\qe\addr.dbf

where STATE=NC&quot;,1) A4 =RETURN