1

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...

6
  • you want to query the data which is present in your excel sheet? Commented Oct 13, 2016 at 10:05
  • no, i need from sql select in excel Commented Oct 13, 2016 at 10:07
  • so you need to write query in excel sheet to fetch the data from Sql ? Commented Oct 13, 2016 at 10:12
  • @K.K I would assume from the question that they want to export the data returned into an excel spreadsheet. Commented Oct 13, 2016 at 10:18
  • 1
    What is the purpose of your export to excel? Commented Oct 13, 2016 at 10:27

2 Answers 2

2

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:

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

Per the SO guidelines: "Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.