Subject Re: [firebird-support] Dynamic SQL statement in stored proc
Author Markus Ostenried
On Fri, Sep 16, 2011 at 12:42, Si Carter <s1cart3r@...> wrote:
> Hi,
>
> I am trying to pass a where clause to a stored procedure to be used in
> a for..select statement, something like:

You're looking for EXECUTE STATEMENT.
See here:
http://www.firebirdsql.org/refdocs/langrefupd15-psql-execstat.html

Example from
\Firebird_2_1\doc\sql.extensions\README.execute_statement.txt


CREATE PROCEDURE DynamicSampleThree (TextField VARCHAR(100), TableName
VARCHAR(100))
RETURNING_VALUES (Line VARCHAR(32000))
AS
DECLARE VARIABLE OneLine VARCHAR(100);
BEGIN
Line = '';
FOR EXECUTE STATEMENT 'SELECT ' || TextField || ' FROM ' || TableName
INTO :OneLine
DO
IF (OneLine IS NOT NULL) THEN
Line = Line || OneLine || ' ';
SUSPEND;
END

HTH,
Markus