Subject Re: [firebird-support] Need a little help with EXECUTE STATEMENT
Author Martijn Tonies
Hello Mike,

> DECLARE VARIABLE tsEndDate TimeStamp;
> begin
> 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?

This ends up being (for V_END_DATE = 2013/1/09)

WHERE D.CREATE_DATE <= 9/1/2013 23:59:59

Do you see the problem? It becomes un-quoted...

Try:

WHERE D.CREATE_DATE <= ''' || tsEndDate || ''''
INTO ...

Where ''' = ' ' ' (with no spaces) and '''' = ' ' ' ' (with no spaces)

With regards,

Martijn Tonies
Upscene Productions
http://www.upscene.com

Download Database Workbench for Oracle, MS SQL Server, Sybase SQL
Anywhere, MySQL, InterBase, NexusDB and Firebird!