1

Boa tarde, gostaria de ver a soma de faturamento de duas datas diferentes(2018 x 2019, mas estou tendo problema com o subselect "Detalhes: "ODBC: ERROR [HY000] [Oracle][ODBC][Ora]ORA-00907: parêntese direito não encontrado"

  Select 
Cast(SUM(VLRBRU) AS VARCHAR(20)) AS "Faturamento 2018",
(Select 
Cast(SUM(VLRBRU) AS VARCHAR(20)) AS "Faturamento 2019"
FROM E140IPV
WHERE CODEMP=1 AND CODFIL=1 AND datger BETWEEN TO_DATE ('2019/01/01', 'yyyy/mm/dd') AND TO_DATE ('2019/12/31', 'yyyy/mm/dd') AND TNSPRO IN ('5101','5103','5904','6101','6109','6124','6401','6501','7101','5949A','6109D','6113','5501','6118');
)

FROM E140IPV
WHERE CODEMP=1 AND CODFIL=1 AND datger BETWEEN TO_DATE ('2018/01/01', 'yyyy/mm/dd') AND TO_DATE ('2018/12/31', 'yyyy/mm/dd') AND TNSPRO IN ('5101','5103','5904','6101','6109','6124','6401','6501','7101','5949A','6109D','6113','5501','6118')

3 Respostas 3

0
  • Na linha 6 não precisa do ;
  • Como não sei o tipo da coluna datger, podemos mudar de onde esta:

    AND datger BETWEEN TO_DATE...
    

    para:

    AND TRUNC(TO_DATE(datger,'yyyy/mm/dd')) BETWEEN TO_DATE...
    

Ficando algo como:

SELECT  CAST(SUM(VLRBRU) AS VARCHAR(20)) AS "Faturamento 2018",
                (SELECT  CAST(SUM(VLRBRU) AS VARCHAR(20)) AS "Faturamento 2019"
                    FROM E140IPV
                  WHERE CODEMP=1 
                       AND CODFIL=1 
                       AND TRUNC(TO_DATE(datger,'yyyy/mm/dd')) BETWEEN TO_DATE ('2019/01/01', 'yyyy/mm/dd') AND TO_DATE ('2019/12/31', 'yyyy/mm/dd') 
                       AND TNSPRO IN ('5101','5103','5904','6101','6109','6124','6401','6501','7101','5949A','6109D','6113','5501','6118')
                )

FROM E140IPV
WHERE CODEMP=1 abela
     AND CODFIL=1 
     AND TRUNC(TO_DATE(datger,'yyyy/mm/dd')) BETWEEN TO_DATE ('2018/01/01', 'yyyy/mm/dd') AND TO_DATE ('2018/12/31', 'yyyy/mm/dd') 
     AND TNSPRO IN ('5101','5103','5904','6101','6109','6124','6401','6501','7101','5949A','6109D','6113','5501','6118')
0

tentei de todo jeito e não vai

"SELECT (SELECT CAST(SUM(VLRBRU) AS VARCHAR(20)) FROM E140IPV WHERE CODEMP=1 AND CODFIL=1 AND datger BETWEEN TO_DATE ('2018/01/01', 'yyyy/mm/dd') AND TO_DATE ('2018/12/31', 'yyyy/mm/dd') AND TNSPRO IN ('5101','5103','5904','6101','6109','6124','6401','6501','7101','5949A','6109D','6113','5501','6118')), (SELECT CAST(SUM(VLRBRU) AS VARCHAR(20)) FROM E140IPV WHERE CODEMP=1 AND CODFIL=1 AND datger BETWEEN TO_DATE ('2019/01/01', 'yyyy/mm/dd') AND TO_DATE ('2019/12/31', 'yyyy/mm/dd') AND TNSPRO IN ('5101','5103','5904','6101','6109','6124','6401','6501','7101','5949A','6109D','6113','5501','6118'))"

0

Não seria mais simples fazer:

SELECT 
    SUM(CASE WHEN year(datger) = 2018 THEN VLRBRU ELSE 0 END) AS "Faturamento 2018",
    SUM(CASE WHEN year(datger) = 2019 THEN VLRBRU ELSE 0 END) AS "Faturamento 2019"
FROM E140IPV 
WHERE CODEMP=1 AND CODFIL=1 AND (year(datger) = 2018 OR year(datger) = 2019) AND
 TNSPRO IN ('5101','5103','5904','6101','6109','6124','6401','6501','7101','5949A','6109D','6113','5501','6118');

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .