I use an excel 2010 template, and an existing SQL 2012 script. Instead of pulling the data and then pasting it into the excel template, I'd like to imbed the sql script in the template. My thought is to have a spot to enter the ID number, and the template updates with just that information. Any suggestions? I enherited the process, but not the knowledge to make this update.
-
So, it sounds like you have an Excel file. You'd like to enter a record id into a field in Excel, Run a Sql 'Script,' and get back the data that corresponds to the ID that you entered. Is that right? Is the script just a SQL query? Or is it some kind of VBA Macro?Ryan B.– Ryan B.2018-08-24 13:54:17 +00:00Commented Aug 24, 2018 at 13:54
-
This thread seems like a perfect fit for your goal. It might be a little much so you may need to spend some time learning how to automate excel with macros and vba.SMor– SMor2018-08-24 13:56:32 +00:00Commented Aug 24, 2018 at 13:56
-
Why dont you use SSIS. you copy your excel template and insert data from your sql script into Excel.mvisser– mvisser2018-08-24 14:02:19 +00:00Commented Aug 24, 2018 at 14:02
-
Greenspark, it is just a sql query, and yes, that sexactly what i'm looking to do.Greg L– Greg L2018-08-28 14:00:15 +00:00Commented Aug 28, 2018 at 14:00
1 Answer
You can import data from SQL Server into Excel without Macro or SSIS package.
1) Save your query as a VIEW in SQL Server. I Called mine V1.
2) Go to Excel and click on your desired sheet and choose "DATA" ribbon and choose "From SQL Server".

3) Fill the your SQL server specs.

4) choose the Database and View.

5) For the next visards just press "Next" and "Finish".
6) If you wanna see changes in your query results just press "Refresh all"

I hope it helps you with your problem. If you want to filter on your data before it loads into Excel this link is useful:Calling a Stored Procedure from Excel with multiple parameters