Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a SQL Server procedure from Excel

I'm using SQL Server 2008 Enterprise. I created a procedure in one database. The procedure is composed of several queries to different databases and the final combined result set is being displayed.

I try to execute it via Excel, so the results will appear automatically in Excel sheet, but I'm getting the error:

The query did not run, or the database table could not be opened. Check the database server or contact your DBA. Make sure the external database is available and hasn't been moved or recognized, then try the operation again

I created a simpler procedure that queries only one database, and the results displayed at the Excel sheet with no issues.

Hence I suspect that, the original procedure failed due to the fact that I'm querying several databases in the procedure, when in the connection details of the "External Data Properties", only one database is mentioned.

My question is - can it be solved? Can I use multiple databases in the procedure and see it in the Excel?

Thanks, Roni

like image 636
Roni Vered Avatar asked Dec 04 '22 06:12

Roni Vered


1 Answers

I transformed the procedure to have Table Variables instead of Temporary tables and I've added "set nocount on" to the beginning of the procedure.

The second action solved the issue.

The first action improved the response time of the procedure.

like image 134
Roni Vered Avatar answered Dec 29 '22 00:12

Roni Vered