Share via

Using SQL commands in MS Excel 2007

Anonymous
2015-04-07T00:03:16+00:00

Hi. How to run SQL query from the Excel 2007 worksheet without using Microsoft Query and VBA? I tried to use SQL.REQUEST function but it only works on MS Excel 2002. What function I need to use in Excel 2007? Thank you.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2015-04-07T15:02:14+00:00

Correct.

In VBA you can either automate Get External Data (you can record a macro while doing it manually to get a good start), or you could use ADO or DAO functions to create a recordset and then use CopyFromRecordset.

I recall using SQL.REQUEST in the early 1990s when I was writing Excel 4 macros.  I seem to remember that it was quite an expensive function and difficult to use, with difficulties whenever strings exceeded 255 characters.  

Excel 97 introduced better methods of importing external data and they have evolved into what we have now as Get External Data.  I wouldn't be surprised if the xlodbc.xla add-in that included SQL.REQUEST would still work if you were able to find a copy.

however, I think the facilities we have today are vastly superior.

Was this answer helpful?

0 comments No comments

7 additional answers

Sort by: Most helpful
  1. Anonymous
    2015-04-07T13:09:13+00:00

    I'm not really sure why he wants it that way. Sorry..

    I've found this link on youtube. May I know how it is done?...

    https://www.youtube.com/watch?v=L\_WqmWM6MKU

    Thank you.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2015-04-07T12:54:11+00:00

    I know no way to do that.  Sorry.

    To do anything with the connection string and the SQL statement in the worksheet would require VBA which you have also ruled out.

    I would again ask why Data > Get External Data, or using VBA, is not a good solution...

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2015-04-07T07:28:11+00:00

    Yes, but my supervisor does not want to use the Data > Get External Data. He wants to run the query from the worksheet. I have the connection string and sql statement written on the worksheet.

    Connection string: DRIVER={Microsoft ODBC for Oracle};UID=xxxxxxx;SERVER=xxxxxx;

    Sql statement = SELECT * FROM table_name

    How do I run this on Excel?

    Thank you.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2015-04-07T07:09:12+00:00

    I'm assuming that your aim is to run a SELECT query and get data into worksheet cells.

    What is the source of the data?

    Why would you not want to use the Data > Get External Data method appropriate to that source?

    (No VBA would be required).

    Was this answer helpful?

    0 comments No comments