bulk insert question

  • I used code below to do bulk insert.

    Since csv file first row is column name.

    How to skip first row?

    BULK

    INSERT TEST

    FROM 'c:\test.csv'

    WITH

    (

    FIELDTERMINATOR = ',',

    ROWTERMINATOR = ''

    )

    GO

  • Quick suggestion, use the FIRSTROW = n, n = number of rows to skip

    😎

  • Eirikur Eiriksson (11/2/2014)


    Quick suggestion, use the FIRSTROW = n, n = number of rows to skip

    😎

    Actually, the n is the number of the row to start with. If row 1 has the headers then you want n to be 2.

  • Lynn Pettis (11/2/2014)


    Eirikur Eiriksson (11/2/2014)


    Quick suggestion, use the FIRSTROW = n, n = number of rows to skip

    😎

    Actually, the n is the number of the row to start with. If row 1 has the headers then you want n to be 2.

    Good catch, thanks Lynn

    😎

  • Just be VERY aware that the rows you skip must have the exact same number and type of delimiters as the rows you want to import or you're in for missing some rows that you didn't want to miss.

    --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 5 posts - 1 through 4 (of 4 total)

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