Bulk Insert

  • Bulk command:

    exec('BULK INSERT sessoes1 FROM ''c:\sgrs\SGRS_SGCTCentral_7_20111111102846.rar_Dir\sessao.txt''

    with (FIRSTROW =2,FIELDTERMINATOR =''|'',

    ROWTERMINATOR =''|'', tablock)')

    Table structure:

    create table Sessoes1(Sessao int, Codrf varchar(5))

  • this errors comes usually if the file is opened While running the bulk insert command.

  • the file is not open.

    It's closed.

  • Re-write the query to match with this example...

    Example:

    DECLARE @bulk_cmd varchar(1000)

    SET @bulk_cmd = 'BULK INSERT AdventureWorks2008R2.Sales.SalesOrderDetail

    FROM ''<drive>:\<path>\<filename>''

    WITH (ROWTERMINATOR = '''+CHAR(10)+''')'

    EXEC(@bulk_cmd) -- Focus here

  • make sure you check for an extra carriage return in your source text file (ie., extra line with no content).

  • I don't think ROWTERMINATOR should be pipe '|'. It should be '\r' or '&#92n' or '\r&#92n'. The latter is default.

    --Vadim R.

Viewing 6 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply