Subject Re: [firebird-support] Re: GROUP BY and JOINs
Author Christian Gütter
Hi Svein,

> I cannot answer your original questions, but since you do not select
> anything from this stored procedure, isn't what you're after
> equivalent to:

> SELECT SUM(PS.Aktueller_Saldo), P.PID, P.Name1, P.Name2, P.ID
> FROM T_Personal_Salden PS
> JOIN T_Personal P ON P.ID = PS.Z_Personal_ID
> WHERE EXISTS(SELECT * FROM P_Hole_Makler_Adressen(P.ID) HMA
> WHERE HMA.O_Personal_Id = P.ID)
> GROUP BY PS.Z_Personal_ID, P.PID, P.Name1, P.Name2, P.ID
> HAVING SUM(PS.Aktueller_Saldo) < 0
> ORDER BY P.PID

> (by the way, why do you have PS.Z_Personal_ID in the group by?)


this is just a test query, so do not expect anything logical from
it ;-)

I put in the stored procedure in order to select from it (later), but the
join failed, while a left outer join worked.

The example can be simplified to a simple join of a table and a
selectable stored procedure.
This does not work:

SELECT PS.Z_Personal_ID, HMA.O_Personal_ID
FROM T_Personal_Salden PS
JOIN P_Hole_Makler_Adressen(PS.Z_Personal_ID) HMA ON
HMA.O_Personal_Id = PS.Z_Personal_ID

Error message:
ISC ERROR CODE:335544348
ISC ERROR MESSAGE: no current record for fetch operation

But with a left outer join, it does work:

SELECT PS.Z_Personal_ID, HMA.O_Personal_ID
FROM T_Personal_Salden PS
LEFT OUTER JOIN P_Hole_Makler_Adressen(PS.Z_Personal_ID) HMA ON
HMA.O_Personal_Id = PS.Z_Personal_ID

So I have a workaround for my problem, but it would be nice if someone
could explain why the second query works and the first does not.

TIA,

Christian