ALTER function [dbo].[AXI_NacenkaProduct] (@ObjectID int) returns decimal(15,2) as begin declare @Result as decimal(15,2) set @result = isnull((select case when isnull(p2406,0)>0 then --цена/стоимость с учетом еи. и валюты на тек. курс. case when isnull((dbo.AXI_SelectExchange(p3095,getdate()) --конвертаем стоимость к еи. *(p2406 --коэффициент ед.изм. поставщика *cast((isnull((select p3628 from attr278 a278 where a278.ObjectID = a109.p879),1) --коэффициент ед.изм. продажи / case when isnull((select p3628 from attr278 a278 where a278.ObjectID = a109.p3756),1) = 0 then 1 else isnull((select p3628 from attr278 a278 where a278.ObjectID = a109.p3756),1) end )as decimal(15,2)) ) ),0) = 0 then 0 else (dbo.AXI_SelectExchange(p3094,getdate())*isnull(p562,0) / (dbo.AXI_SelectExchange(p3095,getdate()) --конвертаем стоимость к еи. *(p2406 --коэффициент ед.изм. поставщика *cast((isnull((select p3628 from attr278 a278 where a278.ObjectID = a109.p879),1) --коэффициент ед.изм. продажи /case when isnull((select p3628 from attr278 a278 where a278.ObjectID = a109.p3756),1)= 0 then 1 else isnull((select p3628 from attr278 a278 where a278.ObjectID = a109.p3756),1) end )as decimal(15,2)) ) ) ) end *100 - 100 else 0 end from attr109 a109 where ObjectID = @ObjectID ),0) return @result end