Subject Re: [firebird-support] Erros in firebird 1.5.x
Author Pavel Menshchikov
Hello Cesar,

CR> I have a query that run fine in firebird 1.03 but in 1.5.2 returns

CR> Invalid token.
CR> Dynamic SQL Error.
CR> SQL error code = -104.
CR> Invalid expression in the select list (not contained in either an
CR> aggregate function or the GROUP BY clause).'

CR> Why works in 1.03 and dont in 1.5.2?
FB 1.5 became more "standard-oriented". And standard says you have to
specify all non-aggregate fields or their position numbers in your
GROUP BY clause.

CR> SELECT I.PROTOCOLO,
CR> I.EMOLUMENTOS,
CR> I.TX_01,
CR> I.TX_02,
CR> I.TX_03,
CR> I.TX_04, I.TX_05,
CR> (SELECT SUM(VALOR) FROM INTIMACOES
CR> WHERE PROTOCOLO = I.PROTOCOLO
CR> AND DATA_RECEPCAO = I.DATA_RECEPCAO
CR> AND TIPO_INTIMACAO = 2) AS CORREIO,
CR> (SELECT SUM(VALOR) FROM INTIMACOES WHERE PROTOCOLO = I.PROTOCOLO
CR> AND DATA_RECEPCAO = I.DATA_RECEPCAO
CR> AND TIPO_INTIMACAO = 1) AS CONDUCAO,
CR> (SELECT SUM(VALOR) FROM INTIMACOES WHERE PROTOCOLO = I.PROTOCOLO
CR> AND DATA_RECEPCAO = I.DATA_RECEPCAO
CR> AND TIPO_INTIMACAO = 3) AS EDITAL FROM INDICE I,
CR> DADOS_DEVEDORE A
CR> WHERE DATA_OCORRENCIA = :DATA
CR> AND OCORRENCIA = 2
CR> AND A.PROTOCOLO = I.PROTOCOLO
CR> AND A.DATA_RECEPCAO = I.DATA_RECEPCAO
CR> GROUP BY I.PROTOCOLO, I.EMOLUMENTOS, I.TX_01, I.TX_02, I.TX_03,
CR> I.TX_04, I.TX_05
CR> ORDER BY I.PROTOCOLO
Hmm, but I see no aggregate functions at all in your "outer" query.
So, why are you groupping here? Do you want distinct rows? "Outer"
GROUP BY clause doesn't affect your correlated sub-queries.

And probably you should convert your implicit join syntaxt to explicit
one: use
from INDICE I inner join DADOS_DEVEDORE A on
A.PROTOCOLO = I.PROTOCOLO and A.DATA_RECEPCAO = I.DATA_RECEPCAO


HTH
--
Best regards,
Pavel Menshchikov
http://www.ls-software.com