Reputation: 2790
I am trying to select a field from MySQL table and remove a substring from that field, and update that field.
For example: VAR1010 I want to replace and update VAR with SHS and the remaining part is the same. The result I am expecting is SHS1010
Here is the code:
SELECT SUBSTR(R.regnumber,4,4) as RegNo from registration R WHERE R.teacheremail='param';
UPDATE registration SET regnumber = 'SHSRegNo' where teacheremail='param';
But it's updating as RegNo
.
Upvotes: 0
Views: 255
Reputation: 4933
use replace
UPDATE registration SET regnumber = replace(regnumber,'VAR','SHS')
where teacheremail='param';
Upvotes: 1
Reputation: 11403
Just do that:
UPDATE registration SET regnumber = concat('SHS', substr(regnumber, 4, 4))
WHERE teacheremail='param';
Upvotes: 2
Reputation: 247730
You can do this in one UPDATE
statement:
UPDATE registration
SET regnumber = concat('SHS', substr(regnumber, 4, 4))
where teacheremail='param';
Upvotes: 3