Created
May 27, 2013 12:04
-
-
Save viniciusss/5656725 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT nfd.cnpj_cpf, nfd.xNome, nfd.xFant, nfd.IE | |
FROM webpdv.nota_fiscal nf | |
LEFT JOIN webpdv.nota_fiscal_dest nfd ON | |
(nfd.nota_fiscal_id = nf.id) | |
WHERE nf.dEmi BETWEEN '2012-01-01' AND '2013-05-28' | |
AND nfd.IE != 'ISENTO' | |
AND EXISTS( | |
SELECT 'X' | |
FROM webpdv.nota_fiscal_prod nfp | |
LEFT JOIN webpdv.produto_caracteristica p ON | |
(p.prdno = nfp.prdno) | |
WHERE (nfp.nota_fiscal_id = nf.id) | |
AND p.revenda = 1 | |
) | |
union | |
SELECT nfd.cnpj_cpf, nfd.xNome, nfd.xFant, nfd.IE | |
FROM webpdv.nota_fiscal nf | |
LEFT JOIN webpdv.nota_fiscal_emit nfd ON | |
(nfd.nota_fiscal_id = nf.id) | |
WHERE nf.dEmi BETWEEN '2012-01-01' AND '2013-05-28' | |
AND nfd.IE != 'ISENTO' | |
AND EXISTS( | |
SELECT 'X' | |
FROM webpdv.nota_fiscal_prod nfp | |
LEFT JOIN webpdv.produto_caracteristica p ON | |
(p.prdno = nfp.prdno) | |
WHERE (nfp.nota_fiscal_id = nf.id) | |
AND p.revenda = 1 | |
) | |
GROUP BY nfd.cnpj_cpf; | |
desc webpdv.nota_fiscal_emit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment