MySQL Forums
Forum List  »  Triggers

Re: copy all values of fields on Update
Posted by: Bob Field
Date: May 22, 2006 12:38PM

create trigger updateLojas after update on producao.lojas
for each row begin

set @stmt = 'update test.lojas_cp set ';

if new.loja_nome != old.loja_nome then
set @stmt = concat(@stmt, 'loja_nome = new.loja_name,');
end if;

if new.loja_cnpj != old.loja_cnpj then
set @stmt = concat(@stmt, 'loja_cnpj = new.loja_cnpj,');
end if

set @stmt = left(@stmt, length(@stmt)-1));
set @stmt = concat(@stmt, ' where loja_numero = new.loja_numero';
prepare stmt1 from @stmt;
execute stmt1;
deallocate prepare stmt1;

if (row_count() = 0) then
insert into test.lojas_cp set loja_numero = new.loja_numero, loja_nome = new.loja_nome, loja_cnpj = new.loja_cnpj;
end if;

end|

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: copy all values of fields on Update
2344
May 22, 2006 12:38PM


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.