Subject Re: GROUP BY and JOINs
Author Svein Erling Tysvær
Hi Christian!

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?)

But - as I said - I have no answer to your original questions.

Set

--- In firebird-support@yahoogroups.com, Christian Gütter wrote:
> 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
> JOIN P_Hole_Makler_Adressen(P.ID) HMA ON 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
>
> When executing that statement, I receive the following error
> message:
>
> "The cursor identified in the update or delete statement is not
> positioned on a row.
> no current record for fetch operation."
>
> Is this an expected limitation of Firebird 1.50?
> If yes, is there a workaround?
> Or is my query just badly written?