views:

399

answers:

2

I have inherited an Excel spreadsheet which contains an external data query. I can edit the query, which provides a list of the columns returned, but it does provide the table that this data comes from. Is there any way to retrieve the actual SQL behind the query?

+1  A: 

I think this may depend on the version of office you're using and the type of external data you're connecting to.

I believe if you're using Office 2003, and you're seeing columns like you say, there may be a SQL icon in the toolbar. Click that to view the SQL used to return the data.

If you're using Office 2007, Go to the Data tab, click connections, then properties, then the definition tab, and change the command text.

However I believe you're using the first method.

This is from what I can remember, so I hope it's correct.

Bravax
The SQL icon is in the toolbar of Microsoft Query. Select a cell within the range that is populated by the query and choose Data -> Import External Data -> Edit Query...
nekomatic
A: 

It could also be somewhat obsfuscated by using an ODBC link or something. Another way to get it is to run SQL Profiler on the SQL Server to see the exact SQL being executed. Of course, this won't help you edit it but you'll know what it is doing.

Chris Latta