dev
dev

Reputation: 181

SQL - data from select in excel file

i have next query

select no,
item
from myTable

and I get next table

no      item
 1        a
 2        b
 3        c
 4        d

I use tsql, Microsoft SQL Server Management Studio. Is there any way to write here some code to export table from my select in excel...

Upvotes: 1

Views: 910

Answers (2)

K.K
K.K

Reputation: 366

from your excel sheet you can create a dynamic connection between a SQL Server database and your Excel workbook.

Follow the steps in below link.

Steps to Connect a SQL Server database to your workbook

Upvotes: 1

iamdave
iamdave

Reputation: 12243

I am not aware of any way to write a query in SSMS and then export the results to excel, but you can connect an excel sheet to SQL Server and run queries into an data table from there using the From Other Sources - From SQL Server menu in the Data tab on the ribbon:

This is good if you want to build on that data within Excel and you need to refresh the data but don't want to update your formulas. There are obviously security implications with this as users of the Worksheet may be able to access other data on your server.

If you want to simply export an Excel file with data in to a file store, you would need to use SSRS and a report subscription. Alternatively, if you simply want to save the results of your query to a file, you can either copy and paste manually or choose to Save Your Results To Text in SSMS:

Upvotes: 2

Related Questions