0
How to sum up the stored quantity of these products to be able to compare with the total order quantity for resale "QTD ORDER". How can I find the stored total and link to the result?
Select:
SELECT ipv.ProdCodEstr 'CÓDIGO DO PRODUTO',
p.ProdNome AS 'NOME PRODUTO',
SUM (CAST(ipv.ItPedVendaQtd AS REAL)) AS 'QTD PEDIDO',
'total por produto' AS 'local 1',
'total por produto' AS 'local 2',
'total por produto' AS 'local 3'
FROM PED_VENDA pv WITH (nolock), STAT_PED_VENDA spv WITH (nolock), ITEM_PED_VENDA ipv WITH (nolock)
LEFT JOIN ESTQ_LOC_ARMAZ EstLoc WITH (nolock) ON (EstLoc.ProdCodEstr = ipv.ProdCodEstr)
LEFT JOIN PRODUTO p on(p.ProdCodEstr = ipv.ProdCodEstr)
WHERE ipv.PedVendaNum = pv.PedVendaNum
AND p.ProdCodEstr = ipv.ProdCodEstr
AND ipv.ItPedVendaServ LIKE 'Não'
AND spv.StatPedVendaCod NOT IN ('08',
'10',
'11',
'12',
'13',
'14',
'15',
'16')
AND pv.PedVendaData BETWEEN '2017-01-01' AND -- Data iinicial
'2017-12-01' -- Data final
GROUP BY ipv.ProdCodEstr,
p.ProdNome
SUM( local 1 + local 2 + local 3 )
– Reginaldo Rigo
@Andretovar: Which column is the location information?
– José Diz
@Andretovar: Table STAT_PED_VENDA relates to which table and through which column? // Tip: In the FROM clause, do not mix old syntax with new syntax.
– José Diz
The column ( Estqlocarmazqtd ) with the stored quantities is in the ESTQ_LOC_ARMAZ table that presents the following primary keys : Empcod and Prodcodestr. I don’t know how to relate the table (ESTQ_LOC_ARMAZ) to the select I made totaling the amount of products in the sales order. @Josédiz
– André Tovar