Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 424
Keven Avatar asked Apr 23 '13 23:04

Keven


2 Answers

This works for me

select * from stuff  update stuff set TYPE1 = TYPE2 where TYPE1 is null;  update stuff set TYPE1 = TYPE2 where TYPE1 ='Blank';  select * from stuff 
like image 66
Sparky Avatar answered Oct 06 '22 05:10

Sparky


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

like image 33
Bob Taylor Avatar answered Oct 06 '22 04:10

Bob Taylor