I created the query where I have a Products table and another inventory (1: N) I need to add the stock of each product has in the inventory table, I made the following query:
select DISTINCT p.ID,IsNull(p.CodigoBarra, '') As
CodBarra,IsNull(p.CodigoAlternativo, '') As
CodAlt,p.Descricao,p.DescricaoAlternativa,f.Descricao as Fabricante,
sum(est.EstoqueAtual) as EstoqueAtual, COUNT(est.EstoqueAtual) as
QtdEsnderecosEstoque from produto p
inner join Fabricante f on f.ID = p.FabricanteID
left join EstoqueLoteLocalizacao est on est.ProdutoId = p.ID
where p.DataExclusao is null and p.EmpresaID = 3
group by p.ID,p.CodigoBarra,p.CodigoAlternativo,p.Descricao,p.DescricaoAlternativa,f.Descricao, est.EstoqueAtual
This Query returns the following:
What I need is that instead of it giving me the 2 records , it group and the current stock there is summed 4000 - -40 and me > display in 1 record only the value of 3960