Microsoft KB Archive/74241

{| = SQL.QUER Returns #REF in Q+E =
 * width="100%"|

Last reviewed: November 2, 1994

Article ID: Q74241

SUMMARY
The function SQL.QUERY is equivalent to the command Select SQL Query. This option is not available unless a query window is open. If you use the EXECUTE function to send the SQL.QUERY command using a DDE channel, #REF will be returned unless there is an open Query in Q+E.

MORE INFORMATION
The following example will NOT work because there is not an open Query in Q+E:

A1   chan=INITIATE(&quot;qe&quot;,&quot;system&quot;) A2   =EXECUTE(chan,&quot;[sql.query('select * from dBASEfile | c:\excel\qe\emp.dbf WHERE ')]&quot;) A3   =TERMINATE(chan) A4   =RETURN The next example WILL work because it sends commands to Q+E that open a query window before attempting to modify the query: A1  chan=INITIATE(&quot;qe&quot;,&quot;system&quot;) A2  =EXECUTE(chan,&quot;[open('d:\excel\xl3\qe\emp.dbf')]&quot;) A3  =EXECUTE(chan,&quot;[sql.query('select * from d:\excel\xl3\qe\addr.dbf where state=NC')]&quot;) A4  =TERMINATE(chan) A5  =RETURN An alternative to opening a file before using SQL.QUERY is to use the OPEN command to send your SQL statement: A1  chan=INITIATE(&quot;qe&quot;,&quot;system&quot;) A2  =EXECUTE(chan,&quot;[open('select * from d:\excel\xl3\qe\emp.dbf WHERE salary > 30000')]&quot;) A3  =TERMINATE(chan) A4  =RETURN The following are other reasons that the line in your macro containing the EXECUTE and SQL.QUERY commands might fail even though the other lines execute correctly:   You are attempting to access a file or table that is not supported by the currently selected driver. An example would be sending the statement &quot;Select * from EMP.XLS&quot; when dBASEFile is set up as your default driver. This can be prevented by including the correct driver name in the Select statement. For example: &quot;Select * from ExcelFile | EMP.XLS&quot;.  You are attempting to access a file that is not in the current directory and you have not included the full path to the file. You are extremely low on memory or system resources.