Hi chaps / chapesses,
I've been playing with BCP using SQL2008R2x64 and have run into an issue. Essentially there is a system I have no control over whatsoever but need to get extracts off. Just about every kind of character appears to have been entered in free text fields somewhere or other, even (surprisingly) tab and ",", |, ^ and just about every useful delineator you would use. Ascii character 167 = § should be OK but when I export this using BCP the § turns into õ.
xp_cmdshell'bcp "[Database].dbo.[Object]" out "D:\Data\Object.txt" /c /t "§" /S "Server\instance" -T'-- Works but the § column delineator character changes to õ.
Looking at the reference for BCP it becomes clear why:
-Ccode_page
Supported for backward compatibility only. Instead, specify a collation name for each column in the format file or in interactivebcp.
Specifies the code page of the data in the data file. code_page is relevant only if the data containschar, varchar, or text columns with character values greater than 127 or less than 32.
Code page value | Description |
ACP | ANSI/Microsoft Windows® (ISO 1252). |
OEM | Default code page used by the client. This is the default code page used by bcp if -C is not specified. |
RAW | No conversion from one code page to another occurs. This is the fastest option because no conversion occurs. |
<value> | Specific code page number, for example, 850. |
So, anything over CHAR(127) will hit trouble. Of course, I could change the /c switch to /w (wide so Unicode file) or /N (native so Unicode file) but I don’t want a Unicode file because it’ll be twice as big!
xp_cmdshell'bcp "[Database].dbo.[Object]" out "D:\Data\Object.txt" /w /t "§" /S "Server\instance" -T'-- Works but means I have a Unicode file - twice as big!
But what was that option above? /C? Sounds great! I’ll just drop the /c or /w or /N and use /C1252 or maybe CRAW or CACP. Except, it doesn’t work! No matter what I type, with a space after the /C or an equals or putting the codepage in “”. Nothing works. It just asks me:
Enter the file storage type of field ExportColumn [char]:
xp_cmdshell'bcp "[Database].dbo.[Object]" out "D:\Data\Object.txt" /C1252 /t "§" /S "Server\instance" -T'-- Doesn't work: Enter the file storage type of field ExportColumn [char]:
xp_cmdshell'bcp "[Database].dbo.[Object]" out "D:\Data\Object.txt" /CRAW /t "§" /S "Server\instance" -T'-- Doesn't work: Enter the file storage type of field ExportColumn [char]:
xp_cmdshell'bcp "[Database].dbo.[Object]" out "D:\Data\Object.txt" /CACP /t "§" /S "Server\instance" -T'-- Doesn't work: Enter the file storage type of field ExportColumn [char]:
xp_cmdshell'bcp "[Database].dbo.[Object]" out "D:\Data\Object.txt" /C "1252" /t "§" /S "Server\instance" -T'-- Doesn't work: Enter the file storage type of field ExportColumn [char]:
xp_cmdshell'bcp "[Database].dbo.[Object]" out "D:\Data\Object.txt" /C "RAW" /t "§" /S "Server\instance" -T'-- Doesn't work: Enter the file storage type of field ExportColumn [char]:
xp_cmdshell'bcp "[Database].dbo.[Object]" out "D:\Data\Object.txt" /C "ACP" /t "§" /S "Server\instance" -T'-- Doesn't work: Enter the file storage type of field ExportColumn [char]:
Eh? What? Is this because the /C function is in fact now defunct and in effect, useless or have I messed something up?
Incidentally, I also tried (after reading: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/52ac08d4-87da-4a4a-a723-a2fee26a375d/issue-on-using-section-sign-as-sql-server-bcp-column-terminator?forum=sqltools)
xp_cmdshell'chcp 1252
bcp "[Database].dbo.[Object]" out "D:\Data\Object.txt" /c /t "§" /S "Server\Instance" -T'
It didn’t export but it did give the message: Active code page: 1252.
Any pointers very gratefully received.
Cheers,
J