Select com periodos independentes

18/11/2005

D2_EMISSAO BETWEEN ´20050704´ AND ´20050704´ AND P4.D_E_L_E_T_ <> ´*´ AND P4.D2_TP IN (´PA´,´MR´) AND P4.D2_TES=SF44.F4_CODIGO AND SF44.D_E_L_E_T_ <> ´*´ AND SF44.F4_DUPLIC IN (´S´) AND SF44.F4_ESTOQUE IN (´S´,´N´) ) AS PERIODO4, SUM(P.D2_TOTAL) TOTALGERAL, SUM(P.D2_ICMSRET) TOTALICM, SUM(P.D2_VALIPI) TOTALIPI, SUM(D2_VALFRE) TOTALFRE, B.B1_DESC DESCRICAO FROM SD2010 P WITH(INDEX=SD20106),SB1010 B WITH(INDEX=SB10101) , SF4010 SF4 WHERE P.D2_EMISSAO BETWEEN´20050701´ AND ´20050704´ AND P.D2_COD=B.B1_COD AND P.D_E_L_E_T_ <> ´*´ AND B.D_E_L_E_T_ <> ´*´ AND P.D2_TP IN (´PA´,´MR´) AND P.D2_TES=SF4.F4_CODIGO AND SF4.D_E_L_E_T_ <> ´*´ AND SF4.F4_DUPLIC=´S´ AND SF4.F4_ESTOQUE<>´´ GROUP BY P.D2_COD, B.B1_DESC ORDER BY B.B1_DESC

Rogerio_amorim