lundi 11 janvier 2016

How to check record isn't containing specific string?

I have a table like this:

// mytable
+----+-------------------------------------------+
| id |                 col                       |
+----+-------------------------------------------+
| 1  | Peter|423421 , Alex Jon|61333             |
| 2  | Barmar|624321                             |
| 3  | Jack|624321 , Ali|312331 , Leonard|624321 |
+----+-------------------------------------------+

I need to check second row if isn't containing 824326, then add this value , Sara|824326 in the end of that. Something like this:

| 2  | Barmar|624321 , Sara|824326               |


Now I want to know, how can I check that field isn't containing thins number 824326 ?

Here is my try, I just need to the condition (to check existing)

UPDATE mytable
SET    col = CASE WHEN col = {:val doesn't exist} // <= How to write this condition?
                   THEN CONCAT(col,':newval')
                   ELSE SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = "It is duplicate";
             END,
WHERE id = 2;

Note1: :newval is this , Sara|824326 in the above query.

Note2: :val is this 824326 in the above query.

Aucun commentaire:

Enregistrer un commentaire