I\'ve spent 2 days trying to export a 75,000 row table containing a large text field of user input data from a SQL server installation. This data contains every plain ascii
The best solution I could come up with is to select all the rows and do a copy as to XML.
The paste it into a notepad file and save it as a XML file. Then open that XML file from excel and voila! Atleast that how I got my file.
Maybe the below link can help you :
Import/Export data with SQL Server 2005 Express
The simplest solution Ive found is to add double quotes in your query;
SELECT '"'+MYCHARACTERDATA+'"' FROM MYTABLE
If your spreadsheet allows you to use a custom text qualifier then you can use a more exotic character like | to avoid double quotes in the text.
Daft..SSMS should export as proper CSV with quoted text fields and properly escaped quotes in those fields.
I'm curious why no one has suggested using SSIS (SQL Server Integration Services) for this process? All of the wizards and tools for Import/Export from within SSMS (SQL Server Management Studio) are absolutely not intended to be comprehensive (and they certainly are not, and yes, there is a lot that Microsoft should have to answer for with the limitations). But SSIS is a very full-featured ETL tool designed to tackle problems exactly like this one. Learning curve can be a little steep, but exporting a table to a comma/quote delimited csv file is not particularly hard.
Might need this add on for Visual Studio in order to have a dev environment to create a package: http://www.microsoft.com/en-us/download/details.aspx?id=42313 (link is for VS 2013, other links are available for other versions of VS).
The easiest way to do this:
Use the Excel Data Import tools
Then Save the imported data to a CSV file. If you want to export a query then save your query as a view
Robert Calhoun's solution did not work for me. We had a lot of text with commas and carriage returns / newlines etc. We used the Export functionality with a few changes to Chris Christodoulou's solution above.
In SQL Management Studio, right click the database and select Tasks -> Export Data.
Then choose SQL Server as the source and Flat File as the destination. Name the file MyFile.csv.
Set the Text qualifier as "
Select 'Write a query to specify the data transfer' and paste in your query. You can leave the next settings as the defaults.
With the data exported, open with Excel and save in the Excel format.