1
I’m making a SELECT
where I join two tables: a stock balance table and another order table.
I’m making a comparison between product balance in stock and balance on purchase orders, only the way I’m doing, the SELECT
is only bringing products that have open purchase order balance in the system.
I need the SELECT
bring not only products that have balance in order of purchases, but also all products of the independent products table whether have placed order of purchases or not. products which have not ordered purchases placed, and SELECT
brings the value 0 in the column.
SELECT DISTINCT SB1.B1_DESC AS PRODUTO
, SUM(SB8.B8_SALDO) AS SALDO
, (SC7.C7_QUANT - SC7.C7_QUJE) AS [SALDO DE COMPRAS]
, SC7.C7_NUM AS PEDIDO
, SB1.B1_EMIN AS [SALDO MINIMO EM ESTOQUE]
FROM SB1010 AS SB1
INNER JOIN SB8010 AS SB8 WITH(NOLOCK) ON SB8.B8_PRODUTO = SB1.B1_COD
INNER JOIN SC7010 AS SC7 WITH(NOLOCK) ON SC7.C7_PRODUTO = SB1.B1_COD
WHERE ISB8.B8_LOCAL = '01'
AND SC7.C7_ENCER <> 'E'
AND SB1.D_E_L_E_T_ = ''
AND SB8.D_E_L_E_T_ = ''
AND SC7.D_E_L_E_T_ = ''
GROUP BY SB1.B1_DESC
, SB1.B1_EMIN
, SC7.C7_QUANT
, SC7.C7_QUJE
, SC7.C7_NUM
OBS: In that SELECT
have a filter SC7.C7_ENCER
which means already completed purchase orders.
It would help if you commented on what each column is and identified each table, because the names are not at all readable.
– Woss
SB1 product table, SB8 product balance table, SC7 purchase order table
– Junior Guerreiro