Update/Increment existing DB with .CSV file

  • I don't know if this can be done or not, but is there a program, or anything I can do to import a CSV, and whatever quantities are in my CSV file, add them to the existing quantities in the database?

    We were doing inventory, and someone commited all the inventory already, and there is still more that needs to be done... I have a CSV file now with updated quantities that I would just like to add to the existing quantities...

    Please let me know what I can do to make this process easier...

    Thanks in advance!

  • olie480 (12/31/2010)


    I don't know if this can be done or not, but is there a program, or anything I can do to import a CSV, and whatever quantities are in my CSV file, add them to the existing quantities in the database?

    We were doing inventory, and someone commited all the inventory already, and there is still more that needs to be done... I have a CSV file now with updated quantities that I would just like to add to the existing quantities...

    Please let me know what I can do to make this process easier...

    Thanks in advance!

    What I would suggest is:

    1. Create a #temporary table with the proper format for the columns in the CSV file.

    2. Bulk insert the csv file into the #temporary table.

    3. Update the real table by joining to the #temporary table.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Thanks Wayne, that is a great solution... I'm still a newbie at SQL, so that never dawned on me... I will definitely try it out.. Thanks for your help!

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

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