Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá meus caros queria retornar os produtos que forem iguais a de um select mas ao fazer isso ele retorna vazio
a query...
select
top 10
names.A1_COD,
names.A1_NOME,
names.A1_VEND,
produtos.ULTCOMP_CLIENTE,
produtos.B1_COD,
produtos.B1_DESC,
produtos.B2_QATU,
produtos.B2_CM1,
produtos.B2_VFIM1,
produtos.B2_VATU1,
teste.D2_QUANT,
teste.D2_PRCVEN,
produtos.ULTCOMP_PRODUTO
from
(select
distinct
D2_COD,
D2_CLIENTE,
D2_QUANT,
D2_EMISSAO,
D2_PRCVEN from SD2010
group by
D2_COD,
D2_CLIENTE,
D2_QUANT,
D2_EMISSAO,
D2_PRCVEN) as teste,
(select
A1_COD,
A1_NOME,
A1_VEND from SA1010
group by
A1_COD,
A1_NOME,
A1_VEND) as names,
(select
A1_COD,
A1_ULTCOM as ULTCOMP_CLIENTE,
B1_COD,
B1_DESC,
B2_QATU,
B2_CM1,
B2_VFIM1,
B2_VATU1,
max(D2_EMISSAO) as ULTCOMP_PRODUTO from SB1010 SB1
inner join SD2010 SD2 on D2_COD = B1_COD
inner join SB2010 SB2 on B2_COD = B1_COD
inner join SA1010 SA1 on A1_COD = D2_CLIENTE
where
B2_QATU > 0
and
(D2_EMISSAO
between
dateadd(mm,-8,getdate()) and dateadd(mm,-2,getdate())
and
SA1.D_E_L_E_T_ <> '*'
and
(SB1.D_E_L_E_T_ <> '*'
and
SB2.D_E_L_E_T_ <> '*'
and
(SD2.D_E_L_E_T_ <> '*'
and
B1_TIPO = 'ME'
and
(B1_COD not in(
select distinct D2_COD from SD2010
where
D2_FILIAL = 01
and
(D2_EMISSAO between dateadd(mm,-2,getdate()) and getdate()
and
D2_TIPO = 'N'))))))
group by
A1_COD,
A1_ULTCOM,
B1_COD,
B1_DESC,
B2_QATU,
B2_CM1,
B2_VFIM1,
B2_VATU1) as produtos
where
names.A1_COD = produtos.A1_COD
and
teste.D2_COD = produtos.B1_COD
and(
teste.D2_CLIENTE = produtos.A1_COD
and
teste.D2_EMISSAO = produtos.ULTCOMP_PRODUTO)
order by
produtos.ULTCOMP_PRODUTO desc;
No where queria colocar um select que retorna apenas um B1_COD ae ele compara se é igual ao do select principal, assim retornando somente este produto.
Resultado:
Carregando comentários...