jumax jumax - 6 months ago 19
SQL Question

SQL UPDATE with LIKE

I was trying to update approx 20,000 records in a table by using statements like this one,
however, I got the message say

0 row(s) affected
so it didn't work.

UPDATE nc_files SET title ="Worklog details" WHERE "log_name" LIKE "%PC01%"


The
log_name
field has all the file names with mixed file extensions and cases ,e.g.

PC01.TXT | Worklog details

PC02.txt | Project Summary

PC03.DOC| Worklog details

PC04.doc| Project Summary


The reason why I need to use
LIKE
is that the updated file only have file name without extension, e.g.

PC01 | Worklog details

PC02 | Project Summary


How do I update records by using
LIKE
?

Answer

The log_name is a field name, remove literal quotes from it -

UPDATE nc_files SET title ="Worklog details" WHERE log_name LIKE "%PC01%"