Updating fields in a table based on records in CSV file

  • Hello everyone.  I know this should be easy but I have never done an update in SQL based on a CSV file so just looking for the proper way to do it via a SQL Query.

    I have a CSV file with one column, "Item ID" and I want to update all my existing records in my dbo.Item table in my SQL ERP database.

    All I want to do is change the IMA_ItemStatusCode column from Active to Estimating for any of those Item ID's in the CSV file.

    Any help is much appreciated.

     

  • Import the CSV into a temporary table in SQL.

    You can use the "Import Flat File" database "Task" to step through the import process.

    Then write your Update query based on the values in your new temporary table.

    Then delete the temporary table if it will not be needed again, or keep for historical reasons.

    • This reply was modified 2 years, 9 months ago by  homebrew01.
    • This reply was modified 2 years, 9 months ago by  homebrew01.
    • This reply was modified 2 years, 9 months ago by  homebrew01.
  • Thank you.  I was able to import my flat file (CSV) to a table called CSVTest.  This CSV had the ItemID column and now an ItemStatusCode column with the value of Estimating.

    From there I then ran this update statement and it appears to have changed all my ItemStatusCode to Estimating based on the records in my CSV file.

    USE TESTDB

    UPDATE dbo.Item

    SET dbo.Item.IMA_ItemStatusCode = dbo.CSVTest.ItemStatusCode

    FROM dbo.Item JOIN dbo.CSVTest ON dbo.Item.IMA_ItemID = dbo.CSVTest.ItemID

    • This reply was modified 2 years, 9 months ago by  MP-iCONN.

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

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