SELECT valuen FROM IReg WHERE idkey  = 'Limit_wyplat_w_gotowce' AND rok = 2015 INTO @l.g;
SELECT valuen FROM IReg WHERE idkey  = 'Limit_wyplat_w_naturze' AND rok = 2015 INTO @l.n;

SET @l.new = GREATEST(@l.g, @l.n);

CREATE TEMPORARY TABLE t_limit AS 
SELECT * FROM IReg WHERE idkey  = 'Limit_wyplat_w_gotowce' AND rok = 2015 ;

INSERT INTO IReg 
SELECT 
  idpath, 'ZFSS_Limit_wyplat', idval, securelevel, notused, valuex, @l.new, 
  valuei, valueb, DATE(NOW()), TIME(NOW()), NULL, valuea, 
  UUID(), 'klucz zastepujacy dwa dotychczasowe klucze "Limit_wyplat_w_ ..." ',   rok, NOW()
FROM t_limit;