How to Export table or query results from Excel using SQL Server
How to Export table or query results from Excel using SQL Server
22 September 2021
Steps to Export SQL Queries results into Excel
-
- Open Microsoft Excel.
- Click on the ‘From Other Sources’ Under ‘Data’.
- Select ‘From SQL Server’ Option.
-
- Once you click on the ‘From SQL Server’ option a new pop-up window appears in front of your screen.
-
- Enter ‘Server Name’ as per your Database connection.
- Select ‘Log on Credentials’ If you are selecting the second option then you need to provide your ‘SQL Server Authentication’ credentials (Username & Password) that are required to connect with the database. If not then click on the next button after giving the ‘Server name’.
- You can find the ‘Server name’ by going through the SQL Server as per the below given image.
-
- Once you click the next button a new pop-up wizard appears in front of your screen.
-
- You will get the list of databases. In my case I have selected the database ‘Essentials’ and based upon the selected database you will get the list of Tables, Views, and Stored Procedures.
- Select the table which you want to export into the excel sheet.
- Click on the ‘Next’ button.
- Then Click on the ‘Finish’ button.
-
- Click on the ‘OK’ button after selecting how you want to show or export your data into the excel sheet. Once you click the ‘OK’ button you will get the desired result as per the below image. As I am going with the ‘Table’ option.
- You can also apply filters on the above results using the excel filters option.
If you want to modify the existing imported results then please follow the below steps
-
- Select the ‘Data’ tab from the excel menu.
- Then click on the ‘Connections’.
- Once you click the ‘Connections’ a new pop-up appears called ‘Workbook Connections’.
-
- Click on the ‘Properties’ and then go under the ‘Definition’ Tab.
- You will see the selected ‘Command Type’ is ‘Table’, you can change it to ‘SQL’ by selecting one of the options from the dropdown.
- Clear the Text which is written under the ‘Command Text’.
- Type any SQL queries under the ‘Command Text’. Here I am simply executing the Select statement. You can also write the command to execute the Stored Procedure, View etc.
-
- Click on ‘OK’ once you enter the command text. Then you will get the Alert proceed with ‘Yes’.
- Then you will get the desired results as per the input ‘Command Text’.