Subject Re: [firebird-support] Need a little help with EXECUTE STATEMENT
Author Mark Rotteveel
On Wed, 9 Jan 2013 08:08:10 -0600, "SoftTech" <miket@...>
wrote:

> tsEndDate = :V_END_DATE || ' 23:59:59';
>
>
> EXECUTE STATEMENT 'SELECT FIRST 1 D.CREATE_DATE
> FROM DEBT D
> WHERE D.CREATE_DATE <= ' || tsEndDate
> INTO :FIRST_CREATE_DATE;
>
> both caused this error.
>
> ISC ERROR CODE: 335544569
> ISC ERROR MESSAGE:
> Dynamic SQL Error
> SQL error code = -104
> Token unknown - line 7, char 141
> 23
>
> What am I doing wrong? Any work arounds?

You are adding it unquoted, so the resulting query is something like

D.CREATE_DATE <= 23-JUN-2012 23:59:59
(I guess I keep forgetting if Firebird will output in this format or in
yyyy-mm-dd when doing string conversion),

While you actually need D.CREATE_DATE <= '23-JUN-2012 23:59:59'
(or better yet to be explicit about the type D.CREATE_DATE <= TIMESTAMP
'2012-06-23 23:59:59')

So tsEndDate = :V_END_DATE || ' 23:59:59'; actually needs to be:

tsEndDate = '''' || :V_END_DATE || ' 23:59:59''' (or add the additional
quotes inside the query where you add tsEndDate)

This will probably also remove the need to do this separately, and might
even fix the original error you started with.

Mark