2

I have a SQL query that returns 1 column. I run it in SQL Server Management Studio 2008R2. I use File\Save Grid Results and create a .TXT file.

My problem is the first record of the file has 3 bytes inserted in front of the data. They three bytes are x'EFBBBF'. This causes problem when I use the file in another process.

I get the same thing wheter I save as .TXT or as .CSV.

Any ideas?

tshepang
  • 12,111
  • 21
  • 91
  • 136
SBCUser666
  • 121
  • 1
  • 6

3 Answers3

10

Found it.

  1. Save Results As...
  2. Choose a folder
  3. Enter a file name
  4. Save button now has a dropdown arrow to the right
  5. Click on dropdown arrow and select Save with Encoding...
  6. Select ANSI
  7. Click OK

The ANSI-encoded file will not contain a UTF-8 BOM.

Sir Crispalot
  • 4,792
  • 1
  • 39
  • 64
SBCUser666
  • 121
  • 1
  • 6
1

kuru kuru na is on the right track, those bytes are the UTF-8 BOM. I haven't found any settings to change the file encoding that Management Studio uses for saving results. I just use Vim to remove the BOM after saving the file. Your favorite text editor may have a similar option, or you could use a tool like iconv if you need to remove the mark or re-encode the file in a script.

Simon
  • 1,197
  • 1
  • 6
  • 14
  • I'll add: it's a little silly that SSMS saves result files in an encoding (UTF-8 w/ BOM) that BULK INSERT doesn't understand. – Simon Jul 18 '11 at 20:49
0

I think it's called a "bom" (byte order mark) signature, which has something to do with telling whatever reads your file that it contains utf characters. I suspect it might be in your SMSS settings somewhere. But at least this is a place to start.

Chains
  • 12,541
  • 8
  • 45
  • 62
  • Went through all the SMSS setting I could find. Nothing about save format. Instead of UTF-8 I need plain MS-DOS text. – SBCUser666 Jul 18 '11 at 21:20