Subject Re: [ib-support] variable not updating in SP
Author Svein Erling Tysvær
Andrew,

> SELECT RDB$FIELD_NAME
> FROM RDB$INDEX_SEGMENTS
> WHERE RDB$INDEX_NAME =
> (
> SELECT RDB$INDEX_NAME
> FROM RDB$INDICES
> WHERE (RDB$INDEX_NAME STARTING WITH 'RDB$PRIMARY')
> AND (RDB$RELATION_NAME = :VAR_TABLENAME)
> )
> INTO :VAR_PKNAME;

My guess is that this for some reason is considered ambiguous. Maybe
rdb$index_name in the where-clause of the subselect is considered to belong
to rdb$index_segments and not rdb$indices.

I would recommend changing to
SELECT RDB$FIELD_NAME
FROM RDB$INDEX_SEGMENTS RS
WHERE (RS.RDB$INDEX_NAME STARTING WITH 'RDB$PRIMARY')
AND EXISTS(SELECT 1 FROM RDB$INDEXNAME RI
WHERE (rI.RDB$INDEX_NAME = RS.RDB$INDEX_NAME)
AND (RI.RDB$RELATION_NAME = :VAR_TABLENAME)
)
INTO :VAR_PKNAME;

but it would be interesting to see if it was enough to qualify your fields.


Set
-not quite Andrew in signing my messages