Copy one column to another sqlserver

UPDATE table SET columnB = columnA

–This will update every row.

UPDATE table_name SET
destination_column_name=orig_column_name
WHERE condition_if_necessary

–This will update rows which satisfy the WHERE clause

UPDATE table1
SET column1 = (
SELECT column2
FROM table2
WHERE table2.id = table1.id
);
Whereby:

table1 = table that has the column that needs to be updated
table2 = table that has the column with the data
column1 = blank column that needs the data from column2 (this is in table1)
column2 = column that has the data (that is in table2)

 

–This will update one column based on value of another table column

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s