How to not import final 2 rows of CSV table

  • Hi All,

    Can anyone tell me the best way to not import the final two rows of a CSV file?

    I have a foreach loop container that imports the CSV files into one SQL Server database, however I do not want to import the final two rows of the file as these are control file rows.

    Many thanks in advance for your support.

    Regards,

    Chris

  • Do they prevent file from being loaded? If not, I guess you can use conditional split to separate them from the rest of the rows.

    Regards

    Piotr

    ...and your only reply is slàinte mhath

  • Hi Piotr,

    Yes they prevent the file from being loaded.

    Regards,

    Chris

  • add a vbscript task before the actual import and open the csv file and delete the last 2 rows and save the file. Then import it and you should be good.

  • Hi hamzajosh,

    Thanks for your suggestion. How would I delete the final two rows in VB?

    Chris

  • I cheat like hell on this type of thing. When I have to do such a thing, I make a BCP format file and either use BCP or BULK INSERT with a max allowed errors setting of 1 or 2 depending on the failure mode that the last 2 lines cause.

    All of that information is located in Books Online under BCP. BCP format files work exactly the same way for either BCP or Bulk Insert.

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

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