Updating Total Column

  • How to update a total column with different values in a table. I want to insert a new column in a table and insert values from other table. How many ways we can achieve this.

    Thank you.

  • Please post table definitions, sample data and expected results as per http://www.sqlservercentral.com/articles/Best+Practices/61537/

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • vrkn82 (9/8/2010)


    How to update a total column with different values in a table. I want to insert a new column in a table and insert values from other table. How many ways we can achieve this.

    Thank you.

    First, for detailed help, please respond to what Gail has asked.

    Your basic steps will be:

    ALTER TABLE <MyTable> ADD <newColumnName> <appropriate data type>

    assuming that you have something to link the two tables together (since you haven't provided the necessary information), one way to get the data into the table would be:

    UPDATE mt

    SET <newColumnName> = o.ColumnName

    FROM <MyTable> mt

    JOIN <TableWithData> o ON mt.<Primary or Unique Column(s)> = o.<Matching Column(s)>

    To get more detailed hit, read the link Gail provided, and then post the requested information.

    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

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

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