senario
进入sqlcmd用:out xxx生成数据文件,由于sqlcmd export to file 默认情况下中文乱码,故用-u(unicode)开关
@echo off & setLocal EnableDelayedExpansion:start@SET DB=AdventureWorks2012sqlcmd -d%DB% -b -iscript.sql -v pa="out.txt" pwd="%cd%" -W -h-1TIMEOUT 3sqlcmd -d%DB% -b -iout.txt -W -h-1 -s^| -u--<strong><strong>由于sqlcmd export to file 默认情况下中文乱码,故用-u(unicode)开关</strong></strong>pauseGOTO start到此,中文正常显示
SQLCMD ERROR
Starting copy...SQLState = S1000, NativeError = 0Error = [Microsoft][SQL Server Native Client 11.0]Unexpected EOF encountered in BCP data-file0 rows copied.Network packet size (bytes): 4096Clock Time (ms.) Total : 1
原因 datafile in Unicode format 用-c开关导入数据会出错
查看
打开-w开关,导入成功
小结
用bcp in or out data时
- ANSI --> -c
- UNICODE-->-w
Using BULK INSERT to Bulk Import Unicode Character Data
USE AdventureWorks2012;GOBULK INSERT myTestUniCharData FROM 'C:\myTestUniCharData-w.Dat' WITH ( DATAFILETYPE='widechar', --unicoode FIELDTERMINATOR=',' ); GOSELECT Col1,Col2,Col3 FROM myTestUniCharData;GO
参考: