2

I am trying to update one of my SQL tables with new columns in my source CSV file. The CSV records in this file are already in this SQL table, but this SQL table is lacking some of the new columns from this CSV file.

I already added the new columns to my SQL table structure via ALTER TABLE. But now I just need to import the data from this CSV file into the new columns. How can I do this? I am trying to use SSIS and SQL Server to accomplish this, but am pretty new to Excel.

3
  • This just seems like a simple update statement to me. Am I missing something? Commented Aug 27, 2010 at 14:12
  • @starsky - Yes when he says "The CSV records in this file are already in this SQL table" I think that isn't strictly true. They are still in the CSV file. But there are records with the same key in the SQL table. Commented Aug 27, 2010 at 14:21
  • Thanks guys. I should have explained. I need to update data for new columns from over 1500 rows so I don't want to do this manually. Why, is there an easy way to do this with SQL? Otherwise I will try Import/Export Wizard in SSIS. Commented Aug 27, 2010 at 16:03

2 Answers 2

4

This is probably too late to solve salvationishere's problem; though I'm posting this for future readers! You could just generate the SQL INSERT/UPDATE/etc command by parsing the csv file (a simple python script will do).

You could alternatively use this online parser: http://www.convertcsv.com/csv-to-sql.htm (Hoping that it'd still be available when you click!) to generate your SQL command. The interface is extremely straight forward and it does the entire job in an awesome way.

Sign up to request clarification or add additional context in comments.

Comments

2

You have several options:

  1. If you are loading the data into a non-production system where you can edit the target tables, you could load the data into a new table, rename the old table to obsolete, and rename the new table to the old table name.

  2. You can load the data into a staging table and then write a SQL statement to update the target table from the staging table.

  3. You can open the CSV file in Excel and write a formula to generate an update script, drag the formula down across all rows so that you get a separate update statement for each row, and then run the separate update statements in management studio.

  4. You can truncate the target table and update your existing ssis package that imports the file to use the new columns if you have the full history in your CSV file.

There are more options, but any of the above would probably be more than adequate solutions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.