Subject Re: [ib-support] Problem with FB's SP
Author Lucas Franzen
The DeerBear schrieb:
>
> Hello,
>
> I have this SP:
>
> CREATE PROCEDURE GETVALUE (TblIndex Varchar(30),
> FldIndex Integer)
> returns (FldValue Varchar(255))
> AS
> declare variable counter Integer;
> begin
> counter = 0;
> for select VALORE FROM Tabella having( Select * FROM DOC_Tabella WHERE
> ID_TABELLA=:TblIndex)
> into FldValue
> counter = counter+1
> if counter < FldIndex then
> skip;
> if counter > FldIndex then
> exit;
> Suspend;
> end
>
> it doesn't recognize the Select * in the having clause.

HAVING is only a valid syntax when you want to compare a value that's
calculated by a GROUP BY expression.
And a lot of other mistakes:
- There's no SKIP in SP's.
- Conditions in an IF statement have to be put in parantheseses,
IF ( EXPRESSION ) THEN ...

I don't see what you want to achieve with this procedure, please tell us
more.

If you want to return just the rows from TABELLE which have a ceratin
number of occurances in DOC_TABELLA, youc an use plain SQL like:

SELECT T.VALORE FROM TABELLA T
JOIN DOC_TABELLA D ON [join expression]
GROUP BY T.TABELLA
HAVING COUNT (*) > YOUR_REQUESTED_COUNT


Regards
Luc.