senario
进入sqlcmd用:out xxx生成数据文件,由于sqlcmd export to file 默认情况下中文乱码,故用-u(unicode)开关
@echo off & setLocal EnableDelayedExpansion :start @SET DB=AdventureWorks2012 sqlcmd -d%DB% -b -iscript.sql -v pa="out.txt" pwd="%cd%" -W -h-1 TIMEOUT 3 sqlcmd -d%DB% -b -iout.txt -W -h-1 -s^| -u--<strong><strong>由于sqlcmd export to file 默认情况下中文乱码,故用-u(unicode)开关</strong></strong> pause GOTO start
到此,中文正常显示
SQLCMD ERROR
Starting copy... SQLState = S1000, NativeError = 0 Error = [Microsoft][SQL Server Native Client 11.0]Unexpected EOF encountered in BCP data-file 0 rows copied. Network packet size (bytes): 4096 Clock 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; GO BULK INSERT myTestUniCharData FROM 'C:\myTestUniCharData-w.Dat' WITH ( DATAFILETYPE='widechar', --unicoode FIELDTERMINATOR=',' ); GO SELECT Col1,Col2,Col3 FROM myTestUniCharData; GO
参考:
- UNICODE与ANSI的区别【转】
- http://www.cnblogs.com/Pickuper/articles/2050427.html
- Use Unicode Character Format to Import or Export Data (SQL Server)
- https://msdn.microsoft.com/en-us/library/ms188289.aspx
时间: 2024-10-11 15:02:16