SQL Server – How to Copy Large Data from Query Result

sql server

In my sql server 2008, after running the query the data return is very huge say in millions. I tried copying but it gives an exception sql memory error. Can you let us know how can i copy the entire data and paste it into excel.

I don't want to export it to txt file as the data is not getting aligned.
So i want to manually copy and paste it into excel.
Please let me know the solution for thhis

Best Answer

You aren't going to be able to copy and paste like you want. However you do have several options. Simplest is to right click on the output and save as a CSV file. That assumes that you don't have an commas in your text data though.

Save Results As

Your next option (and probably best) is to use the export wizard. Right click on your database name, then Tasks, then Export Wizard

Where is the wizard?

Your source will be the database you right clicked on.

Source

Pick an excel destination.

Destination

Select the Write a query to specify the data to transfer.

Pick a query

Paste in your query

Paste in your query

You can change the sheet name in your spreadsheet here.

Select source tables

Next is the list of mappings for you to review

List of mappings

And from here you can either run the package immediately or save the SSIS package for later use/fixes. If your export doesn't work the first time and you are at all familiar with SSIS I would save the package so you can go into it and make corrections outside the wizard.

Save and run options

Then just hit finish and finish again.