December 23, 2009 | In: Work
SQL special Char replacement
I do myself run into this problem far to many times. Special Characters that end up being al jarbled up in my Database. I am talking about french special characters but I am sure that most other languages like Scandinavian and German chars would fall in under the same category. So over the course of the last few years I have been building my own replacement script that really comes in handy when I need to quickly find and replace chars across my database. Bare in mind that I built this as I went along. So there are missing ones still. But they are real easy to find. Just insert one record for each weird char that you run into through your app, then update this SQL script accordingly.
UPDATE table
SET
field = REPLACE( field, 'é', 'é' ),
field = REPLACE( field, 'É', 'É' ),
field = REPLACE( field, 'è', 'è' ),
field = REPLACE( field, 'È', 'È' );
field = REPLACE( field, 'ô', 'ô' ),
field = REPLACE( field, 'Ô', 'Ô' ),
field = REPLACE( field, 'è', 'ê' ),
field = REPLACE( field, 'â', 'â' ),
field = REPLACE( field, 'î', 'î' ),
field = REPLACE( field, 'Î', 'Î' ),
field = REPLACE( field, 'ÃÂ', 'à' ),
field = REPLACE( field, 'ç', 'ç' );
Sharing is caring, right? And what better time to do so then these days.
