Guido Guido - 1 year ago 70
SQL Question

Changing a specific char in a MySQL string

I have a table with a series of permissions, and I need to change every user's permission to Y in a given position p in the string, is there a SQL command I can use or do I have to write a program/script to do it?

Answer Source

You can use a combination of concat and substring in MySQL:

mysql> select concat(substring('12345',1,3),'A',substring('12345',5));
| concat(substring('12345',1,3),'A',substring('12345',5)) |
| 123A5                                                   |

You can replace '12345' with the name of your column.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download