1

I have a CSV file including a list of employees, where some of them includes German characters like 'ö' in their names. I need to create a temp table in my SQL Server 2017 script and fill it with the content of the CSV file. My script is:

CREATE TABLE #AllAdUsers(
    [PhysicalDeliveryOfficeName] [NVARCHAR](255) NULL,
    [Name] [NVARCHAR](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [DisplayName] [NVARCHAR](255) NULL,
    [Company] [NVARCHAR](255) NULL,
    [SAMAccountName] [NVARCHAR](255) NULL
)

--import AD users
BULK INSERT #AllAdUsers
    FROM 'C:\Employees.csv'
    WITH
    (
        FIRSTROW = 2,
        FIELDTERMINATOR = ',',  --CSV field delimiter
        ROWTERMINATOR = '\n',   --Use to shift the control to next row
        TABLOCK
    )

However, even though I use "Nvarchar" variable type with the collation of "SQL_Latin1_General_CP1_CI", the German characters are not seem OK, for instance "Kösker" seems like:

"K├╢sker"

I've tried many other collations but couldn't find a fix for it. Any help would be very much appreciated.

Dale K
  • 25,246
  • 15
  • 42
  • 71
Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82

2 Answers2

0

First, convert the Encoding of your source CSV file to UTF-8 with Notepad++ and try to import it again.

It worked for me.

Taner
  • 1
  • 1
  • that could be another solution, thanks for the suggestion, but it requires a manual procedure in the middle. The CSV file here was being generated by another application and I needed to read it immediately via a SQL job after another application stopped running. – Eray Balkanli Mar 03 '23 at 18:56
0

Adding codepage=65001 to the bulk insert query fixed the issue:

--import AD users
BULK INSERT #AllAdUsers
    FROM 'C:\Employees.csv'
    WITH
    (
        FIRSTROW = 2,
        CODEPAGE = '65001',
        FIELDTERMINATOR = ',',  --CSV field delimiter
        ROWTERMINATOR = '\n',   --Use to shift the control to next row
        TABLOCK
    )
Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82