Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Automate multiple queries to execute once and spoo

Author  Topic 

msrahman
Starting Member

4 Posts

Posted - 2015-04-10 : 12:02:12
Hi all,
I have some SQL queries, that I need to automate them all and execute them and spool the data to excel on different tab's. Like Script 1, the data should be spooled to Tab1, Script 2 to Tab2......etc.

But the issue here is;
1) I don't have SQLCMD to run by already created batch script. How and from can I install the SQLCMD?
2) I don't have permissions to create/run a SP.
3) Is there any other way that I can Automate and execute the sql scripts in SQL Server.

I tried this, but its not working either.
--SPOOL C:\Users\a521\Documents\D_C\Test.xls
--@C:\Users\a521\Documents\D_C\Mart_Record_Counts_Test.dsql;
--SPOOL OFF

Appreciate any feedback.

msrahman
Starting Member

4 Posts

Posted - 2015-04-10 : 14:27:33
At lease, can someone tell me as to how can I run the sql queries, which will output the data to excel spreadsheet. And each script should go into each tab in Excel sheet. Script 1 -- tab 1, ,, Script 2 ---tab 2............and so on.

Appreciate for your reply back. This is bit urgent and I am stuck in between.

Thanks!
Go to Top of Page

MichaelJSQL
Constraint Violating Yak Guru

252 Posts

Posted - 2015-04-10 : 14:51:08
there are plenty of ways to do this. From excel

1) go to the data tab
2) select other source and select from Microsoft Query - this will get you a query tool and you can query whatever you have access to so long as you have access to the table.
Go to Top of Page

msrahman
Starting Member

4 Posts

Posted - 2015-04-10 : 16:11:06
Thanks for the reply Michael. But when I do that I am getting an error "Client Driver version is not supported".

Is there a way in SQL Server, that we can spool the data to excel rather than going the other way?
Any suggestions?
Go to Top of Page

msrahman
Starting Member

4 Posts

Posted - 2015-04-10 : 16:23:44
I was able to get into it, BUT
It looks bit complicated, but this is not what I am looking for. I want to execute the queries from MS Visual Studio, and display the output on excel spreadsheet.
Go to Top of Page
   

- Advertisement -