Board index » delphi » TQuery error - "Could Not Find Object"

TQuery error - "Could Not Find Object"

I have a TQuery with SQL similar to the following:

INSERT INTO table1 (field1,field2,field3...)
SELECT field1,field2,field3... FROM table2 T
WHERE
  T.DateTime =
( SELECT max( DateTime ) FROM table2
  WHERE
     DateTime <= :pDateTime
)

The apparent complexity of the query is unimportant; the "Could Not Find
Object." error occurs when including the
last line ("DateTime <= :pDateTime") in the SQL statement, which contains a
parameter.

TQuery.ParamCheck is set to True and I am setting the parameter's value
using TQuery.ParamByName before
calling TQuery.ExecSQL.

One last (and probably most significant) twist: the SQL works perfectly if I
comment out the first line ("INSERT...") and use it as a select, calling
TQuery.Open;

Any ideas about what this error could mean?  Are there some issues using
parameters with INSERT that I need to be aware of?

Thanks,
Alan

 

Re:TQuery error - "Could Not Find Object"


Quote
Alan McKeen wrote:

> I have a TQuery with SQL similar to the following:

> INSERT INTO table1 (field1,field2,field3...)
> SELECT field1,field2,field3... FROM table2 T
> WHERE
>   T.DateTime =
> ( SELECT max( DateTime ) FROM table2
>   WHERE
>      DateTime <= :pDateTime
> )

> The apparent complexity of the query is unimportant; the "Could Not Find
> Object." error occurs when including the
> last line ("DateTime <= :pDateTime") in the SQL statement, which contains a
> parameter.

> TQuery.ParamCheck is set to True and I am setting the parameter's value
> using TQuery.ParamByName before
> calling TQuery.ExecSQL.

> One last (and probably most significant) twist: the SQL works perfectly if I
> comment out the first line ("INSERT...") and use it as a select, calling
> TQuery.Open;

> Any ideas about what this error could mean?  Are there some issues using
> parameters with INSERT that I need to be aware of?

> Thanks,
> Alan

Try

INSERT INTO table1
 (SELECT field1,field2,field3... FROM table2 T
 WHERE
   T.DateTime =
 ( SELECT max( DateTime ) FROM table2
   WHERE
      DateTime <= :pDateTime
 ))

HTH

Other Threads