Subject RE: [IBO] Param Value lost within query
Author Svein Erling Tysvær
>Hi
>I've statement which uses twice one parameter:
>
>with qTest do begin
>SQL.Text := 'insert into NEW_TABLE ('
>+ ' ID,'
>+ ' MY_DATE,'
>+ ' MY_FOREIGN_KEY)'
>+ ' select'
>+ ' gen_id(gen_test, 1),'
>+ ' :date_param,'
>+ ' (select first 1 t.id from foreign_table t'
>+ ' where t.year = extractyear(:date_param))'
>+ ' from rdb$database';
>
>ParamByName('date_param').AsDate := Date();
>ExecSQL;
>end;
>
>and this query inserts <null> into MY_DATE field!
>SQL_MONITOR:
>PARAMS = [ Version 1 SQLd 2 SQLn 2
>[DATE_PARAM] = <NULL> < SQLType: 571 SQLLen: 4 Addr: 24109038 > !!!
>[DATE_PARAM] = '24 lut 2012' ]
>
>qTest is a TIB_Query, IBO 4.9.14.32

Are you sure that both params are of the same type, Tomek? E.g. if MY_DATE is defined as DATE whereas extractyear takes a TimeStamp parameter, then IBO believes them to be different parameters (I had a similar problem a month or so ago, I think I tried to use the same parameter name for a CHAR and VARCHAR field). I'm assuming MY_DATE is defined as a DATE, so try changing your query to:

SQL.Text := 'insert into NEW_TABLE ('
+ ' ID,'
+ ' MY_DATE,'
+ ' MY_FOREIGN_KEY)'
+ ' select'
+ ' gen_id(gen_test, 1),'
+ ' :date_param,'
+ ' (select first 1 t.id from foreign_table t'
+ ' where t.year = extractyear(cast(:date_param as Date)))'
+ ' from rdb$database';

HTH,
Set