Matteo Tassinari Wrote:
-------------------------------------------------------
>
> IF NEW.nome_utente IS NULL OR NOT NEW.nome_utente
> THEN
> SET NEW.id_user_sgs = 1;
> SET NEW.nome_utente = 'SYSTEM';
> END IF;
> END $$
>
Nome_utente is certainly a string (varchar).
If string is not empty, NOT string gives always true.
Look at simple example:
drop table xxx;
create table xxx(
name varchar( 10 )
);
insert into xxx values( null ), ( 'tom' ), ( 'john' );
select name,
case when name is null or not name
then 'null or 0'
else 'not null and not 0'
end result
from xxx;
+------+-----------+
| name | result |
+------+-----------+
| NULL | null or 0 |
| tom | null or 0 |
| john | null or 0 |
+------+-----------+
3 rows in set, 2 warnings (0,00 sec)
mysql> show warnings;
+---------+------+------------------------------------------+
| Level | Code | Message |
+---------+------+------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'tom' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'john' |
+---------+------+------------------------------------------+
2 rows in set (0,00 sec)
MySql tries to convert the string to a number, but when conversion is impossible the result of casting is 0.
Edited 1 time(s). Last edit at 05/26/2012 12:29PM by irek kordirko.