inserting data

  • h

  • Can't really insert at this point, but you can run update statements on the existing rows.

    You could literally do one at a time:

    UPDATE A SET lname = 'lee' WHERE id = 1

    Then repeat for each pair.

    If you are not super familiar with SQL this is the most straight forward way.

    I hope this helps!

  • h

  • The best suggestion I would have for you would be to either start over using the import data tool available with Sql Management Studio, or you can create a temp table with your data and then update your data like this:

    UPDATE A SET lname = TT.lname FROM TempTable TT WHERE TT.ID = ID

    If you go through the trouble of setting up the temp table, you might as well TRUNCATE A (deletes everything in A) and import all the data at once.

    Are the columns in separate files, or do you have all the data in one file?

    If it is just one file you would have the most luck using the import tool.

    Open up Sql Server Management Studio -> Connect to your Instance

    Right click on your database -> Go to Tasks -> Import Data...

    Go through the wizard and it should be pretty easy for you.

  • h

  • Then use the import tool to import each file and then run the following update scripts.

    For last name:

    UPDATE A set lname = LN.lname FROM LastName LN WHERE LN.id = id

    For first name:

    UPDATE A set fname = FN.fname FROM FirstName FN WHERE FN.id = id

    When you do the import and you end up with a different table name just substitute the table names.

    Hopefully this helps.

  • ashwinboinala (12/27/2011)


    i have entered id values

    1

    2

    3

    4

    5

    6

    i dont really find any relevance to first insert these id values . you can populate the destination table irrespective of this column values in destination table OR you can add id int identity column later after population of dest. table.

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • By far the easiest way is to truncate your new table, change your ID to identity (if it isn't already), then just insert your data. Don't over complicated this, it should really simple.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (12/28/2011)


    By far the easiest way is to truncate your new table, change your ID to identity (if it isn't already), then just insert your data. Don't over complicated this, it should really simple.

    +1

    I am surprised why it took so much time for this suggestion. It should be the first suggestion.

Viewing 9 posts - 1 through 8 (of 8 total)

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