Special characters displaying incorrectly after BULK INSERT

后端 未结 1 772
Happy的楠姐
Happy的楠姐 2020-12-15 17:17

I\'m using BULK INSERT to import a CSV file. One of the columns in the CSV file contains some values that contain fractions (e.g. 1m½f).

相关标签:
1条回答
  • 2020-12-15 17:34

    You need to BULK INSERT using the CODEPAGE = 'ACP', which converts string data from Windows codepage 1252 to SQL Server codepage.

    BULK INSERT dbo.temp FROM 'C:\Temp\file.csv' 
    WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '\n', CODEPAGE = 'ACP');
    

    If you are bringing in UTF-8 data on a new enough version of SQL Server:

    [...] , CODEPAGE = '65001');
    

    You may also need to specify DATAFILETYPE = 'char|native|widechar|widenative'.

    0 讨论(0)
提交回复
热议问题