If I need to replace all mentions of "TOTA"
in a column with nothing would I use the following concept? It seems simple but all the tutorials that I find are not in plain enough English for someone who picked up SQL last week.
Update Tablename
set indcode =case when indcode in('TOTA', then 'blank' else 'leave it alone' End);
You should set to null for assign blank value
Update Tablename
set indcode = NULL
where indcode ='TOTA';
and use where for filter the row to update
if you need a set of value for filter you can use a IN clause eg
Update Tablename
set indcode = NULL
where indcode in ('TOTA', '0', '000000');
or for complex case you can use case when ..
Update Tablename
set indcode = case when 'TOTA' then NULL
when '0' then '000000'
else indcode
END
You were missing a equal sign and a closing parentheses, and as written you would have updated it to the string blank, not an empty string, and finally, you need to decide if you want it to be updated to an empty (zero-length) string, or to the built-in database value called null, which represents, in all relational databases, that the value is not known or is unspecified (as opposed to explicitly being an empty or zero-length string.)
To update to an empty (zero-Length) string, write'
Update Tablename
set indcode = case when indcode = 'TOTA' then ''
else indcode end;
but you really don't need to update the ones to be left alone, so just add a filter (a Where clause) with that predicate expression
Update Tablename
set indcode = ''
Where indcode = 'TOTA'
If you really want to update it to Null, and not to an empty string, then first check and make sure that the column indCode is set to allow nulls, and write:
Update Tablename
set indcode = Null
Where indcode = 'TOTA'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.