Subject Re: [firebird-support] Stored procedure to work with specified table/fields?
Author Helen Borrie
At 11:17 PM 18/06/2004 +0000, you wrote:
>Hi All,
>
>I'd like to write a stored procedure that is generic and independent
>of hard coded table and field names. For instance:
>
>create procedure spTest(sTable VarChar(255), sField VarChar(255))
> returns (pResult Integer)
>as
>Begin
> select :sField from :sTable
> where this = that
> into :pResult;
>
> suspend;
>End
>
>This barfs with a parsing error.

Yup. SPs need to know at compile time what database objects they are
working with.

>Is there anyway to do this?

EXECUTE STATEMENT lets you build up a custom DSQL string at run-time and
execute the contents of the string. See the release notes AND ALSO the
caveats.

>I
>need to write a series of stored procedures to work against
>temporary tables that are created and dropped on the fly so the
>table names won't be known until runtime.

This is *not* a recommended technique. Create "permanent" temporary tables
and implement a session ID using a generator. You can housekeep these
tables at idle times...

/heLen