-1

Im new in all of this and Im having a dificult time doing the following: After an Alter Table where Im adding a new column Im updating the values based on another column. What a want to do is where there is a null after the process put the name "LIV".

How would you do it?

Thanks in advance

Code:

ALTER TABLE TEST1 ADD COLUMN UBIC2 STRING;
UPDATE TEST1 
SET UBIC2 = UBIC
WHERE ZONA ="X1" or ZONA ="X2"

Tried to use an IFNULL(UBIC2, "LIV")

2 Answers2

0

You could update the table with a case expression. Also, since you want to update all the rows of the table, you can lose the where clause:

UPDATE test1
SET    ubic2 = CASE WHEN zona IN ('X1', 'X2') THEN ubic ELSE 'LIV' END
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

Tried this ?

UPDATE test1
SET    ubic2 = CASE WHEN zona IN ('X1', 'X2') THEN ubic ELSE 'LIV' END
where 1=1
Mr.Batra
  • 787
  • 1
  • 5
  • 11