SELECT A.cst_pis, A.ALIQUOTAPIS AS ALIQ_PIS, ROUND(SUM(A.TOTALPRODUTO),2) AS VL_REC_BRT, ROUND(SUM(A.BASEPIS),2) AS VL_BC_CONT, (ROUND(sum(A.BASEPIS*(A.ALIQUOTAPIS/100)),2)) AS VL_CONT_APUR FROM PRODUTOS_NOTASAIDA A INNER JOIN LVSAIDAS B ON A.PRIMARIA = B.PRIMARIA LEFT JOIN tributacaopiscofins C ON A.CODTRIBPISCOFINS = C.ID left join CFOP P on A.CFOP=P.CFOP WHERE B.EMISSAO BETWEEN('2013-07-02') AND ('2013-07-02') AND B.EMPRESA in (1) and B.modelo in (1,2,4,55) and B.PARTICIPAPIS='S' and P.PARTICIPAPISCOFINS='S' AND A.CST_PIS IN ('01', '02', '03', '04', '05', '49') AND B.CANCELADO='N' and A.ALIQUOTAPIS>0 GROUP BY A.cst_pis, A.ALIQUOTAPIS UNION ALL SELECT A.id_produto,A.aliquota,A.cst_pis, A.ALIQUOTAPIS AS ALIQ_PIS, ROUND(SUM(A.QTDXUNIT-A.DESCONTO+A.ACRESCIMO-A.DESCONTO_ITEM),2) AS VL_REC_BRT, ROUND(SUM(A.QTDXUNIT-A.DESCONTO+A.ACRESCIMO-A.DESCONTO_ITEM),2) AS VL_BC_CONT, (ROUND(SUM((A.QTDXUNIT-A.DESCONTO+A.ACRESCIMO-A.DESCONTO_ITEM)*(A.ALIQUOTAPIS/100)),2)) AS VL_CONT_APUR FROM MOVDIARIO A INNER JOIN PRODUTO B ON A.ID_PRODUTO = B.CODITEM LEFT JOIN tributacaopiscofins C ON B.COD_TRIBPISCOFINSVENDAS = C.ID WHERE A.EMISSAO BETWEEN('2013-07-02') AND ('2013-07-02') AND A.TIPO = 'V' AND A.EMPRESA in (1) AND (A.SITUACAO = '' OR A.SITUACAO = ' ' OR A.SITUACAO IS NULL) AND A.CST_PIS IN ('01', '02', '03', '04', '05', '49') and A.ALIQUOTAPIS>0 GROUP BY A.id_produto,A.ALIQUOTAPIS, A.aliquota, A.cst_pis select sum(QTDXUNIT-DESCONTO+ACRESCIMO-DESCONTO_ITEM) from movdiario where id_produto=3973 and emissao ='2013-07-02' and tipo='V' and situacao=''