Importing into Sql Server from CSV file

  • Hello Everybody,

    I am importing an csv file into Sql Server straight forward no data cleansing or anything and i noticed everyday it misses the last row in the CSV file.

    Has anybody come accross this if so is there anything that i can do to get that row.

    ANY HELP ON THIS IS GREATLY APPRECIATED.

    Thanks In advance....

  • Could be the code or could be missing the final line terminator in the data. Dunno because you've posted neither...

    --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)
    Intro to Tally Tables and Functions

  • Jeff,

    There is no code involved here i am doing a Straight dts import from Flat file source to Sql Server table as destination.In this process last row in the csv file is not getting imported.

    Hopefully this helps.

    Thanks In Advance....

  • Then, most likely, the last row does not have a final row termination character... a very common mistake. I don't know enough about DTS to force it to load, either. I always end up appending the required character to the file with a DOS command (COPY)

    --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)
    Intro to Tally Tables and Functions

  • Jeff,

    can you help me with the dos command..so that i can force the final row teminate character.

    Let me know if you need anything from my side that helps you to help me..

    THanks,

  • Sure... create a file called "CR.txt" and store a single blank line in it. Almost any editor including NotePad can do this just by opening a new file, pressing ENTER 1 time, and saving the file as "CR.txt".

    Then the DOS copy command can add the carriage return in the file to any other file...

    COPY somefilename.someext+CR.txt somefilename.someext

    You can also get sophisticated with VBS and the FSO (File System Object) but that's way beyond what I think needs to be done 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)
    Intro to Tally Tables and Functions

  • Jeff.

    That worked...thanks very much!

    Just for my understanding...

    Basically we are adding a empty line or space after the last row...right.

    Thanks Very Much once again...

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

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