I'm trying to make a sum of the result of another operation. Below is the code I'm trying to do
select
distinct
(SELECT(SUM(CAST(ROUND(ppre.Valor_Custo, 2) as decimal(18,2))) )) *
(select isnull(sum(case when e.Quantidade < 0 then 0 else e.Quantidade
end),0)from Estoque e
inner join deposito d on d.ID = e.ID_Deposito and d.ID_Empresa in (1,2)
and
d.Ativo = 1
where e.ID_Produto = prod.ID)
as 'Custo total'
FROM Produto prod
inner join Produto_Empresa ppre on ppre.ID_Produto = prod.ID
group by prod.id
This is the result of the query:
How do I turn these two results into one?
Note: I already tried to add SUM
but it did not work.