Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / General / SQL Server Tools / July 2008

Tip: Looking for answers? Try searching our database.

Stray control characters in CSV Export from Management Studio

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kwdavids - 15 Jul 2008 14:26 GMT
I have a very simple result set displayed in a Grid in Microsoft SQL
Server Management Studio (2005) that I want to save as a CSV file. I
right click on the grid, select Save Results As... and save the file.
The file looks like this in a text editor:

1,1,1
2,2,2
3,3,3
...

But when I try to open it in Excel, it's not parsed right. Examination
with a Hex editor shows a leading Hex ff fe, plus a null between each
character.

Here's what I got from Management Studio:

ff fe 31 00 2c 00 31 00 2c 00 31 00 0d 00 0a 00 32 00 2c 00 32 00 2c
00 32 00 0d 00 0a 00 33 00 2c 00 33 00 2c 00 33 00 0d 00 0a 00 34 00
2c 00 34 00 2c 00 34 00 0d 00 0a 00 35 00 2c 00 35 00 2c 00 35 00 0d
00 0a 00 36 00 2c 00 36 00 2c 00 36 00 0d 00 0a 00 37 00 2c 00 37 00
2c 00 37 00 0d 00 0a 00 38 00 2c 00 38 00 2c 00 38 00 0d 00 0a 00 39
00 2c 00 39 00 2c 00 39 00 0d 00 0a 00 31 00 30 00 2c 00 31 00 30 00
2c 00 31 00 30 00 0d 00 0a 00

This is what is normal:

31 2c 31 2c 31 0d 0a 32 2c 32 2c 32 0d 0a 33 2c 33 2c 33 0d 0a 34 2c
34 2c 34 0d 0a 35 2c 35 2c 35 0d 0a 36 2c 36 2c 36 0d 0a 37 2c 37 2c
37 0d 0a 38 2c 38 2c 38 0d 0a 39 2c 39 2c 39 0d 0a 31 30 2c 31 30 2c
31 30

It's a real pain not being to simply open these files in Excel.

Kevin
kwdavids - 15 Jul 2008 15:27 GMT
...

OK, I learned that the format is Unicode. Two things are broken in my
mind. First SQL server can't save an ASCII CSV file. Excel is broken
in that it can't open a Unicode CSV file.

Keivn
Erland Sommarskog - 15 Jul 2008 23:32 GMT
> OK, I learned that the format is Unicode. Two things are broken in my
> mind. First SQL server can't save an ASCII CSV file. Excel is broken
> in that it can't open a Unicode CSV file.

You can save an ASCII CSV file. In the Save dialogue, note the small
arror beside Save. Use this to select Save with Encoding.

I was able to open a CSV file in Unicode format with Excel 2007, but I
had to open it from within Excel. When I double-clicked it, I got
everything in column A.

Signature

Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

Roy Harvey (SQL Server MVP) - 15 Jul 2008 15:46 GMT
I think your CSV file is being saved as UNICODE.

Roy Harvey
Beacon Falls, CT

>I have a very simple result set displayed in a Grid in Microsoft SQL
>Server Management Studio (2005) that I want to save as a CSV file. I
[quoted text clipped - 30 lines]
>
>Kevin
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.