Subject Re: [firebird-support] Select query from IB6.0 to FB 1.5 RC4
Author Arno Brinkman
Hi Luiz,

> I am migrating an app from IB 6.01 to FB1.5 RC4 and I am getting the next
> error:
>
> "ISC ERROR CODE:335544569
>
> ISC ERROR MESSAGE:
> Dynamic SQL Error
> SQL error code = -104
> Invalid expression in the select list (not contained in either an
aggregate
> function or the GROUP BY clause)"
>
> My Select Query is the next. It was working in IB 6.01.
>
> What am I doing wrong?

You've got an invalid expression in your select list :-)

Let's make your query more readable :

SELECT
B.isdiu,
C.Nome as Medico,
F.Nome as Servico,
sum(A.Stotal) as Tot_clin,
(SELECT count(S1.Nr) FROM Porc_med S1
WHERE S1.Nr = C.Nr and S1.porcD>0) as Fator_div,
^^^^^^
D.porcD as PorcMedico,
C1.TOT_DESP as Despesa,
sum(A.stotal*D.porcd/100) as Part_MED,
sum(A.stotal*(D.porcd/100)*E.IR/100) as IR,
sum(A.stotal*(D.porcd/100)*E.ISS/100) as ISS,
sum(A.stotal*(D.porcd/100)*(100-E.IR-E.ISS)/100) as LIQ,
C1.TOT_DESP*D.porcd/100.0/(SELECT count(S1.Nr)
FROM Porc_med S1
WHERE S1.Nr = C.Nr and S1.porcD>0) as Desp_med,
^^^^^
sum(A.stotal*(D.porcd/100)*(100-E.IR-E.ISS) /
100 * C1.GLOSA / 100) as GLOSA
FROM
Medint C
left join GRUPO_MED C1 on C1.Nr=C.Nr and C1.Diurno='T'
join relfat B on C.Nr=B.medint
join fatura A on A.nrf=B.nrf and A.stipo<>4
join porc_med D on D.Nr=C.Nr and D.nserv=A.stipo
join servbase F on A.stipo=F.nserv
join Planos E on E.ident_cp=B.ident_cp
WHERE
B.Data>=:di and
B.Data<:df and
C.Nr=:v_med
GROUP BY
C.Nome,
B.isdiu,
F.Nome,
C1.TOT_DESP,
D.porcd
ORDER BY 2,1 desc,3


C.Nr isn't part of the GROUP BY clause and due bugs inside FB1.0 IBx you can
get even wrong results with this query!
Add C.Nr to the GROUP BY clause or change it into a aggregate function
MAX(C.Nr), MIN(C.Nr) depending on what it should be.

Regards,
Arno Brinkman
ABVisie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird links :
http://www.firebirdsql.com
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/


Nederlandse firebird nieuwsgroep :
news://80.126.130.81