SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for ASP.Net, SQL Server, Reporting Services, T-SQL, Windows, AWS, SAP HANA and ABAP


SQL Server Export Query Results to Excel with Column Names

This SQL Server tutorial shows how to export query results to Excel with column names in SQL Server Management Studio 2014.

If you execute an SQL query on SQL Server Management Studio (SSMS), you can customize SSMS for SQL Server 2014 to export query results to MS Excel with column names in a single step configuration. Here is how SQL developers can customize SQL Server 2014 Management Studio options which enable to save query results and query result field names as an Microsoft Excel file in .csv format.

Open Microsoft SQL Server 2014 Managment Studio and connect to database instance and database you want to run your SQL query.

On SSMS menu follow the menu options: Tools > Options...

customize SQL Server Management Studio options
Customize SQL Server Management Studio options: Tools > Options

When SSMS Options configuration screen is displayed, drill down the options menu until you reach following "options for displaying the result set in grid format".
Drill through Options > Query Results > SQL Server > Results to Grid

Make sure that you marked "Include column headers when copying or saving the results"
This option will enable SQL programmers to export SQL query results to Excel with column names.

SQL Server Management Studio options for displaying result set
SQL Server 2014 Management Studio options for displaying the result set in grid format

After configuring SSMS options for displaying result set and including column names when copying or saving query results, let's make an example.

Execute a SQL Select statement using query editor screen on SQL Server 2014 Management Studio.
When query execution is completed and results are displayed switch to grid results tab.
Right click on the top left corner of the results table. I marked the area with number 1 in red color.
From the context menu, choose menu option Save Results As..., I again put a mark with number 2 in red.

SSMS
Export SQL query results from SQL Server to Excel using SSMS (SQL Server Management Studio)

When the Save As dialog screen is displayed, enter the target file folder and file name and choose the file format as .csv
When you save the SQL query results using this method and open the file in Microsoft Excel, you will see the column names of the query result set.

If you frequently export data from SQL Server to Excel you can customize SQL Server Management Studio options as illustrated in this SQL tutorial. If SQL Server data to export to Excel is not too big, you can again use Copy (after this configuration) or Copy with Headers (Ctrl+Shift+C) to export query output with column names from SQL Server to Excel or to other programs.



SQL Server

SQL Server 2019 Installation
download SQL Server 2019
download SQL Server 2017
download SQL Server 2016
download SQL Server 2014
download SQL Server 2012
MacOS ve SQL Server 2019


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.