Subject Re: [firebird-support] Execute Statement problem with timestamp
Author Helen Borrie
At 12:18 PM 24/11/2011, you wrote:

>I've a little problem with a sql statement:
>
>s_stmmain = 'insert into ' || :s_stmtable || '(kd_id, fnr, fbeginn, fende)
>values ('
>
> || :t_timestamp || ',' || cast(:i_fnr as varchar(4)) || ','
>
> || '1111' || ',' || '2222' || ')';
>
> execute statement s_stmmain;
>
>t_timestamp is a timestamp value and has a blank character. Now, I have test
>it with quotest '''', but it does not work.

Two problems here:
1. Don't use the colon prefix when attempting to concatenate a variable in an exe-string. The colon is to be used when the variable is passed in a direct SQL statement ONLY.

2. When passing an apostrophe as a literal you have to "escape" it with another apostrophe. That is, two single quote characters.

Try this:

s_stmmain = 'insert into ' || s_stmtable || ' (kd_id, fnr, fbeginn, fende)
values (''' <--- 3 apostrophes
|| t_timestamp
|| ''', ' <--- 3 apostrophes + comma + 1 apostrophe
|| cast(i_fnr as varchar(4))
|| ','
|| '1111'
|| ', '
|| '2222' || ')';

./heLen