September 8, 2010 at 1:34 am
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.
September 8, 2010 at 1:58 am
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
September 8, 2010 at 5:34 am
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
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply