if (select count(*) from Relations where TableName='v_NonPayedServicesByContract' and ColName='BgNonPayedServiceWithDisc')<>0 then Update Relations SET Function='SUM(BgNonPayedServiceWithDisc)',Suma='SUM(qrData.Дължима сума)' where TableName='v_NonPayedServicesByContract' and ColName='BgNonPayedServiceWithDisc' end if;