Subject Re: [IBO] SQL won't execute
Author Helen Borrie
Hello Josh,

Look, I've spent about two hours so far on this, attempting to explain what
you've got wrong here (there is much about it that is wrong) but I'm
eternally getting lost in all these parameters.

In summary,
1 - parameterised queries are a client-side thing. A parameter for a DSQL
query substitutes for the value in a column - it's a constant value that
the application has to know about *before* the query is submitted to the

2 - Neither IBO (interpreting for the API) nor the server can work with
invalid SQL. This is an issue here, specifically with the grammar for
supplying constants in lieu of column specs for select queries.

3 - You also need to review the logic of the "query that worked when I ran
it directly". It might have "worked" in the sense that it didn't error,
but you can't join on null.

4. You can't "pass" the parameters of one query to another as
parameters. You can assign the _value_ of a column in one dataset to the
_value_ of a parameter.

5. You can vastly simplify this whole operation by making your insert spec

insert into table (columnA, columnY)
values (:columnX, :columnY)

Note that, if you're using a triggered generator to assign a PK and you're
not using GeneratorLinks, then you need to _exclude_ the PK from the insert

In the BeforeExecute event of the ib_dsql, do
with MyDSQL do
if not Prepared then Prepare;
ParamByName('columnX').AsWhateverType := GetTheValueOfColumnX;
ParamByName('columnY').AsWhateverType := GetTheValueOfColumnY;

If you can't do the GetTheValue tasks by reading fields, then just write
brief functions to do it.