Subject Re: [firebird-support] exists(EXECUTE STATEMENT ...
Author Helen Borrie
At 09:24 AM 13/08/2004 +0200, you wrote:
>Hi,
>
> (Firebird 1.5.1 CS on Linux)
> in PSQL the following statement doesn't work:
>
> [...]
> "SQL" = 'SELECT "Id" FROM "SomeTable" WHERE "Fieldname" ='||
> "ParameterOfSP";
>
> IF (not exists(EXECUTE STATEMENT "SQL")) THEN
> [...]
>
>
> Did I make a syntax error

:-)

>or is this a missing feature of firebird?

EXECUTE STATEMENT is a PSQL statement syntax in its own right. You can't
use it as some sort of extended "variable" to substitute into syntax of a
DSQL statement (or any other statement at all).

On the other side of the coin, an EXISTS() predicate can not take any kind
of argument except a subquery.

Another problem you have here is that, when a SELECT statement is used in
PSQL, either directly or via EXECUTE STATEMENT, it must always return its
results to variables.

The following would be legal ---


DECLARE aID integer;
[...]

"SQL" = 'SELECT "Id" FROM "SomeTable" WHERE "Fieldname" ='||
"ParameterOfSP";
aID = -99;
if the "Id" column returns only one value:
EXECUTE STATEMENT "SQL" INTO :aID;

or, if the query would return multiple values:

FOR EXECUTE STATEMENT "SQL" INTO :aID DO
BEGIN
[...]
END

Back to the drawing board? You'll find the description and examples in the
v.1.5 Release Notes.

By the way, did you know that these infernal double quotes are not required?

/heLen