Subject Re: [ib-support] Re: Problem with FB's SP
Author Lucas Franzen
Andrew,


> To start with, I don't see my message and the replies.

I'll send it to you directly, too.

>
> I had to look into the group to find them.
>
> > I don't see what you want to achieve with this procedure, please
> tell us
> > more.
> >
>
> Ok, say you have 2 tables:
>
> DOC_TABLE composed of
> 1) ID_Table
> 2) ID_Value
> 3) ID_Document
>
> TABLES composed of
>
> 1) ID_TABLE
> 2) VALUE
>
> ID_VALUE in DOC_TABLE means the number of values in the "subtable"
> represented by ID_TABLE.
> To be clearer, immagine that TABLES has 4 elements with the same
> ID_TABLE and a different VALUE value for each record.
> If I have an ID_VALUE of 3 then I want the third of the 4 records.

Now that's what I call complicated.
What's the 3rd record in a relational database?
There's nothing like an absolut position of records.

>
> So, I just want to count the records and fetch the one I want.

Ok, you want to step through the subtable and take the record you want?

Try this

CREATE PROCEDURE GETVALUE (
TblIndex Varchar(30),
FldIndex Integer
)
RETURNS (FldValue Varchar(255))
AS
declare variable counter Integer;
begin
counter = 0;
FOR SELECT VALUE from DOC_TABLE
WHERE ID_TABLE = :TblIndex
INTO :FldValue
DO BEGIN
COUNTER = COUNTER + 1;
IF ( COUNTER = FldIndex ) THEN
BEGIN
SUSPEND;
EXIT;
END
END
END

Luc.