---
---Skus que no estan en la lista de precios
---
select
a.strCamGen, a.strCodLin, a.strAtributo, a.NroPedidos, d.strDescripcion
from
(
select a.strCamGen, b.strCodLin, b.strAtributo, COUNT(*) as NroPedidos
from tbl_pedcab a
inner join tbl_peddet b on a.strTipDoc = b.strTipDoc and a.strNumDoc = b.strNumDoc
where
a.strCamGen = '201909'
group by a.strCamGen, b.strCodLin, b.strAtributo
) a
left join tbllistasprecios b on b.strCampaña = a.strCamGen and b.strCodLin = a.strCodLin and b.strCodPre = '0002'
inner join tblSku c on c.strCodLin = a.strCodLin
inner join tblproductos d on c.strReferencia = d.strReferencia
where
b.strCodLin is null
order by
strAtributo, strCodLin