Subject Re: [firebird-support] Query stop working after upgrade from 2.1.5 to 2.1.6
Author Svein Erling Tysvær
>Hi,
>
>I overcome this issue with this query
>
>select
> ke.I_ID_GRUPY,
> ke.C_SYMBOL,
> (
> select first 1 cs.C_OPIS from T_CENY_SKLADNIKI as cs
> left join T_CENY_W_OKRESIE as cwo on (cwo.I_ID_CENY_OKRS =
>cs.I_ID_CENY_OKRS)
> where cs.C_SYMBOL = ke.C_SYMBOL and cwo.I_ID_CENNIKA = any (select
>I_ID_CENNIKA from R_KOSZTY as kk where kk.I_ID_KOSZTY = any (select ID
>from IDY_DO_ZAPYTANIA))
> ) as C_OPIS_X,
> sum(ke.N_VALUE) as N_VALUE_SUMA,
> sum(ke.N_VATIN) as N_VATIN_SUMA,
> sum(ke.N_COSTNETTO) as N_COSTNETTO_SUMA,
> sum(ke.N_COSTBRUTTO) as N_COSTBRUTTO_SUMA,
> ke.SI_WYKLADNIK, ke.SI_IDJEDNOSTKA, ke.SI_STPOTYPE, ke.SI_CURRENCYPERVALUE
>from
> R_KOSZTY k
> left join R_KOSZT_OKRESY as ko on (ko.I_ID_KOSZTY = k.I_ID_KOSZTY)
> left join R_KOSZT_ELEMENTY as ke on (ke.I_ID_KOSZT_OKRESY =
>ko.I_ID_KOSZT_OKRESY)
>where ke.SI_USEINSUMMARY = 1 and k.I_ID_KOSZTY = any (select ID from
>IDY_DO_ZAPYTANIA)
>group by ke.I_ID_GRUPY, ke.C_SYMBOL, C_OPIS_X, SI_WYKLADNIK,
>SI_IDJEDNOSTKA, SI_STPOTYPE, SI_CURRENCYPERVALUE
>order by max(ke.I_ORDER_INDEX)
>
>I have to change "where kk.I_ID_KOSZTY = ko.I_ID_KOSZTY" to
>"kk.I_ID_KOSZTY = any (select ID from IDY_DO_ZAPYTANIA)".

Good to hear you overcome your issue. I took a look at your database and query this evening, and to my surprise your original query executed fine on 2.5.2 (26539)! (well, not yielding any result due to IDY_DO_ZAPYTANIA being empty, but removing that table gave 12 rows). An alternative query you could use (up to you to choose, you could try both if this is just a small test database and you have a bigger real database), is:

with tmp (C_SYMBOL, I_ID_KOSZTY, C_OPIS_X) as
(select cs.C_SYMBOL, kk.I_ID_KOSZTY, min(cs.C_OPIS)
from T_CENY_SKLADNIKI as cs
join T_CENY_W_OKRESIE as cwo
on cwo.I_ID_CENY_OKRS = cs.I_ID_CENY_OKRS
join R_KOSZTY kk on cwo.I_ID_CENNIKA = kk.I_ID_CENNIKA
group by 1, 2)
select
ke.I_ID_GRUPY,
ke.C_SYMBOL,
t.C_OPIS_X,
sum(ke.N_VALUE) as N_VALUE_SUMA,
sum(ke.N_VATIN) as N_VATIN_SUMA,
sum(ke.N_COSTNETTO) as N_COSTNETTO_SUMA,
sum(ke.N_COSTBRUTTO) as N_COSTBRUTTO_SUMA,
ke.SI_WYKLADNIK, ke.SI_IDJEDNOSTKA, ke.SI_STPOTYPE, ke.SI_CURRENCYPERVALUE
from R_KOSZTY k
join R_KOSZT_OKRESY as ko on ko.I_ID_KOSZTY = k.I_ID_KOSZTY
join R_KOSZT_ELEMENTY as ke on ke.I_ID_KOSZT_OKRESY = ko.I_ID_KOSZT_OKRESY
join IDY_DO_ZAPYTANIA z on k.I_ID_KOSZTY = z.ID
left join tmp t
on ke.C_SYMBOL = t.C_SYMBOL
and ko.I_ID_KOSZTY = t.I_ID_KOSZTY
where ke.SI_USEINSUMMARY = 1
group by ke.I_ID_GRUPY, ke.C_SYMBOL, t.C_OPIS_X, SI_WYKLADNIK, SI_IDJEDNOSTKA, SI_STPOTYPE, SI_CURRENCYPERVALUE
order by max(ke.I_ORDER_INDEX)

HTH,
Set