问题
All I am using BCP for import export and getting "Invalid character value for cast specification" error for only 1(first row of export) row while trying to import back. Table Structure Col1 -- Numeric(19,0) Col2 -- NVARCHAR(400) Col3 -- NVARCHAR(400) I am using following commands
FOR Export
EXEC master..xp_cmdshell 'bcp "SELECT TOP 10 Col1, Col2, Col3 FROM Server.dbo.TableName" queryout C:\Data\File.dat -S Server -T -t"<EOFD>" -r"<EORD>" -w'
Same way I am generating a FORMAT file
EXEC master..xp_cmdshell 'BCP Server.dbo.TableName format nul -S Server -T -w -f "C:\Data\File.fmt" -t"<EOFD>" -r"<EORD>" '
Now when I try importing data back into SQL Server table I am getting error "Invalid character value for cast specification" Error logs shows me something like this
#@ Row 1, Column 1: Invalid character value for cast specification @#
?1000 Mytestdataunicoded nothing
Now from where this ? added in starting of my column data is still unknown.
I am able to import successfully when trying importing with format file, also able to import successfully when using switch -c, but for some purposes we must use -w switch to do that.
来源:https://stackoverflow.com/questions/31339664/bcp-import-error-invalid-character-value-for-cast-specification