[sql] Update values from one column in same table to another in SQL Server

I'm trying to overwrite values that are found in TYPE1 with values that are found in TYPE2.

I wrote this SQL to try it out, but for some reason it isn't updating:

select * from stuff

update stuff
set TYPE1 = TYPE2
where TYPE1 is null;

update stuff
set TYPE1 = TYPE2
where TYPE1 ='Blank';

http://www.sqlfiddle.com/#!3/a4733/17

Any reason why my values in TYPE1 are not updating?

This question is related to sql sql-server sql-update

The answer is


update TABLE_1 a set COLUMN_1 = (select COLUMN_2 from TABLE_1 b where a.ID = b.ID)

UPDATE `tbl_user` SET `name`=concat('tbl_user.first_name','tbl_user.last_name') WHERE student_roll>965

UPDATE TABLE_NAME SET COLUMN_A = COLUMN_B;

Much easier. At least on Oracle SQL, i don't know if this works on other dialects as well.


You put select query before update queries, so you just see initial data. Put select * from stuff; to the end of list.


This answer about updating column from a part of another column in the same table.

update T1
set domainname = (New value) --Example: (SELECT LEFT(TableName.col, CHARINDEX('@',TableName.col)-1) STRIPPED_STRING FROM TableName where TableName.col = T2.Emp_ID)
from TableName T1
INNER JOIN
    TableName T2
ON 
    T1.ID= T2.ID;

Your select statement was before the update statement see Updated fiddle


UPDATE a
SET a.column1 = b.column2
FROM myTable a 
INNER JOIN myTable b
on a.myID = b.myID

in order for both "a" and "b" to work, both aliases must be defined


Examples related to sql

Passing multiple values for same variable in stored procedure SQL permissions for roles Generic XSLT Search and Replace template Access And/Or exclusions Pyspark: Filter dataframe based on multiple conditions Subtracting 1 day from a timestamp date PYODBC--Data source name not found and no default driver specified select rows in sql with latest date for each ID repeated multiple times ALTER TABLE DROP COLUMN failed because one or more objects access this column Create Local SQL Server database

Examples related to sql-server

Passing multiple values for same variable in stored procedure SQL permissions for roles Count the Number of Tables in a SQL Server Database Visual Studio 2017 does not have Business Intelligence Integration Services/Projects ALTER TABLE DROP COLUMN failed because one or more objects access this column Create Local SQL Server database How to create temp table using Create statement in SQL Server? SQL Query Where Date = Today Minus 7 Days How do I pass a list as a parameter in a stored procedure? SQL Server date format yyyymmdd

Examples related to sql-update

Update some specific field of an entity in android Room How to perform update operations on columns of type JSONB in Postgres 9.4 MySQL - UPDATE multiple rows with different values in one query How to update multiple columns in single update statement in DB2 Update Multiple Rows in Entity Framework from a list of ids Update MySQL using HTML Form and PHP CodeIgniter query: How to move a column value to another column in the same row and save the current time in the original column? mysql after insert trigger which updates another table's column Update values from one column in same table to another in SQL Server I want to use CASE statement to update some records in sql server 2005