I suppose it depends on the encoding of the input file.
You used SINGLEBLOB
and according to MSDN it causes data to be returned as varbinary(MAX)
. Your file was probably saved using a non-unicode encoding, so when it was imported data into nvarchar
column, SQL interpreted it incorrectly. Changing the type allowed characters to be read correctly. Please try to encode the file with UTF-16 and try to import data into a nvarchar(MAX) variable.
Update
I tried to recreate the issue You described. I've saved a text file with ANSI encoding, run the import script and got the output similar to the one You posted in Your question. Then, I converted the file to UCS-2 Little Endian encoding and after running the script I got correct output.
To sum it up, if You want to use importing with SINGLEBLOB
option, just convert the file with data to use UCS-2 Little Endian encoding and it should work correctly with nvarchar
SQL type.
Reference links: