SELECT IF((SELECT I1.valuei FROM IReg I1 WHERE I1.idkey="Rodzaj_platnika" LIMIT 1)=0,(SELECT MAX(valuea) AS VALUE  FROM IReg WHERE idpath = 'INT\\SYSTEM\\MOTLAWA\\DaneFirmy' and idkey='Pelna_nazwa'),(SELECT MAX(valuea) AS VALUE  FROM IReg WHERE idkey='Platnik_nazwisko')) as wynik 