Subject Re: [firebird-support] Dynamic name in a stored procedure
Author Helen Borrie
At 06:00 AM 15/11/2007, you wrote:


>DECLARE VARIABLE DOFULL SMALLINT;
>DECLARE VARIABLE SOURCEVIEW Char(20);
>BEGIN
> DOFULL = 1;
> IF (DOFULL = 1) then
> SOURCEVIEW = 'PASWORD_VIEW_FULL';
> ELSE
> SOURCEVIEW = 'PASWORD_VIEW_LITE';
> FOR SELECT
> DESCRIPTION,
> COMPANYNAME
> FROM :SOURCEVIEW <--- not happy with this
> INTO
> :DESCRIPTION,
> :COMPANYNAME
> DO BEGIN
> SUSPEND;
> END
>END
>
>Can someone please tell me where this is wrong?

You can't pass an object as a parameter to a stored procedure. Apart from the consistency issues (which this restriction is designed to prevent), database objects are not surfaced in the SQL language as data types.

>And what the correct SQL syntax should be?

There is no "correct SQL syntax" for passing object references as arguments to stored procedures.

> I'm trying to get my stord procedure to return results from one of 2 views based > on a condiiton. SourceView should have one of two view names.

There is a way to do this. Study the documentation in the v.1.5 release notes for EXECUTE STATEMENT. It was implemented for situations like this. Essentially, you pass the object name as a VARCHAR(31) variable and construct your statement by concatenation at run-time.

Warning: unfortunately, with EXECUTE STATEMENT you can perform DDL operations in stored procedures. EXECUTE STATEMENT is not intended for this purpose so don't attempt it. It's one of those "Give a man enough rope.." cases.

./heLen