BULK INSERT with inconsistent number of columns

前端 未结 5 1513
名媛妹妹
名媛妹妹 2020-12-10 07:21

I am trying to load a large amount data in SQL server from a flat file using BULK INSERT. However, my file has varying number of columns, for instance the first row contains

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 08:13

    Try specifying a ROW terminator along with your field terminator.

    BULK INSERT #t 
    FROM '' 
    WITH  
    ( 
      DATAFILETYPE = 'char', 
      KEEPNULLS, 
      FIELDTERMINATOR = '#',
      ROWTERMINATOR = '\n' --Or whatever signifies the end of a row in your flatfile.
    ) 
    

    More info on this can be found here:

    http://msdn.microsoft.com/en-us/library/ms191485.aspx

提交回复
热议问题