Text file to Temp Table

  • Hi

    I am trying to copy a data from text file to temp table using bulk insert but it gives me Error.

    My text file contain data like

    123233,123433

    123333,434344

    122333,234343

    232333,233434

    and i store this text file to C:\Users\mypc\Desktop\test.txt

    in sql server management studio i ran this query

    create table #PersonalData

    (Addressid varchar(50),

    Name varchar(50)

    )

    go

    USE tempdb;

    GO

    BULK INSERT #PersonalData

    FROM 'C:\Users\Unnati\Desktop\test.txt'

    WITH (

    FIELDTERMINATOR = ',',

    rowterminator ='',

    KEEPNULLS

    );

    GO

    but it gave me Below Error Message

    Msg 4863, Level 16, State 1, Line 1

    Bulk load data conversion error (truncation) for row 2, column 1 (Addressid).

    Msg 4863, Level 16, State 1, Line 1

    Bulk load data conversion error (truncation) for row 3, column 1 (Addressid).

    Msg 4832, Level 16, State 1, Line 1

    Bulk load: An unexpected end of file was encountered in the data file.

    Msg 7399, Level 16, State 1, Line 1

    The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.

    Msg 7330, Level 16, State 2, Line 1

    Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".

    Please Help me what i have to do to load the data from text file.

    i appreciate for any help

    Thank you.

  • I think the problem is with the line that specifies the rowterminator. After I duplicated the error you got, I simply removed the rowterminator specification. The BULK INSERT then used the default row terminator of a newline '\r', and worked fine.

    Here's the documentation for BULK INSERT

    msdn.microsoft.com/en-us/library/ms188365.aspx

    Brian Kukowski
  • Thank you very much..

    i got my answer

  • unnati.patel513 (2/3/2012)


    Thank you very much..

    i got my answer

    Ok... so what was the answer? Two way street here. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 3 (of 3 total)

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