如何将数据从管道分隔的.csv文件更新/插入表中

时间:2019-01-09 09:41:06

标签: sql-server tsql

我已将数据从.csv文件导入到临时表中,就像

ID          DEPARTMENT      DESIGNATION       LOCATION     REGION       STATE

Test19768   Barclays|Citi Bank|Ireland      developer   NULL    NULL    NULL

并且必须像这样在EMp表中更新/插入

ID          DEPARTMENT      DESIGNATION   LOCATION        REGION        STATE
Test19768   Barclays        developer       NULL            NULL        NULL
Test19768   Citi Bank|      NULL            NULL            NULL        NULL
Test19768   Ireland         NULL            NULL            NULL        NULL

需要为每个用户ID插入多个管道分隔值。由于版本14,我们不能使用STRING_SPLIT。

1 个答案:

答案 0 :(得分:0)

检查此

BULK INSERT TempTable
    FROM 'C:\CSVData\your.csv'
    WITH
    (
        FIRSTROW = 2,
        FIELDTERMINATOR = '|',  --CSV field delimiter
        ROWTERMINATOR = '\n',   --Use to shift the control to next row
        ERRORFILE = 'C:\CSVDATA\ErrorRows.csv',
        TABLOCK
    )

Related Post