Export SQL Query Data to Excel

Export SQL query data to Excel

I don't know if this is what you're looking for, but you can export the results to Excel like this:

In the results pane, click the top-left cell to highlight all the records, and then right-click the top-left cell and click "Save Results As". One of the export options is CSV.

You might give this a shot too:

INSERT INTO OPENROWSET 
('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=c:\Test.xls;','SELECT productid, price FROM dbo.product')

Lastly, you can look into using SSIS (replaced DTS) for data exports. Here is a link to a tutorial:

http://www.accelebrate.com/sql_training/ssis_2008_tutorial.htm

== Update #1 ==

To save the result as CSV file with column headers, one can follow the steps shown below:

  1. Go to Tools->Options
  2. Query Results->SQL Server->Results to Grid
  3. Check “Include column headers when copying or saving results”
  4. Click OK.
  5. Note that the new settings won’t affect any existing Query tabs — you’ll need to open new ones and/or restart SSMS.

How to added the SQL query used generate the excel file in DATAGRIP IDE?

There is no possibility to include the SQL tab automatically. But every grid has it's own "View Query" option where you can see and copy the needed SQL.

Sample Image

To have this tab, please create a feature request here: https://youtrack.jetbrains.com/issues/DBE

How to export select query data into excel file using Oracle query?

You need to use SPOOL and you can not directly write to .xls file, You need to write data to .csv file and open it in Excel.

set sqlformat csv
spool d:\your_file.csv
select * from your_table;
spool off;

Cheers!!

How to save sql query result to excel?

The manual way, if your in SQL Server Management Studio (SSMS), is to just highlight the rows and columns and paste it in Excel or you can right-click and save as a CSV file and open it in Excel.

To bring over the headers, you want to:

  1. Click on the Tools menu option.
  2. Click on Options -> Query Results -> Sql Server -> Results to Grid
  3. Tick Include Column Headers when Copying or Saving the Results

Then do your copy and paste.



Related Topics



Leave a reply



Submit