SQL Server Management Studio – Export Query Results to Excel

The easiest way I’ve found involves two steps:

Adjust SSMS Settings

  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.

Now next time you run a query, do this

  1. Make sure the results are displayed in a grid (CTRL+D or Query->Results To->Results to Grid)
  2. Right click in the grid, and click Select All
  3. Right click in the grid again & click Copy
  4. Open up a new Excel spreadsheet, and paste the data in
  5. Do a global search & replace, replacing “NULL” with an empty string.

Voila!

I had tried before with SSMS’s export to CSV feature, and it just didn’t escape data the way I needed it to.

8