MySQL Forums
Forum List  »  General

Re: Replace String Function
Posted by: Andrew Gilfrin
Date: March 01, 2005 03:12PM

You need to use CASE like so...

mysql> create table test (code varchar(1)) //
Query OK, 0 rows affected (0.27 sec)

mysql> insert into test values ('a'),('b'),('c') //
Query OK, 3 rows affected (0.05 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select code from test //
+------+
| code |
+------+
| a |
| b |
| c |
+------+
3 rows in set (0.00 sec)

mysql> select case code when 'a' then 'apple' when 'b' then 'baseball' when 'c' then 'cookie' end as code from test //
+----------+
| code |
+----------+
| apple |
| baseball |
| cookie |
+----------+
3 rows in set (0.00 sec)

OK with 3 elements but a bit long winded if you had many more, but does the job none the less.

Andrew Gilfrin
MySQL Stroed Procedure Tutorials and info at http://www.mysqldevelopment.com

Options: ReplyQuote


Subject
Written By
Posted
March 01, 2005 01:53PM
March 01, 2005 02:37PM
Re: Replace String Function
March 01, 2005 03:12PM
March 01, 2005 04:51PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.