I'm trying to use a parameter within my dynamic sql query, but just can't get it to work. I simplified my code to highlight only the part I'm struggling with.
I first create 't1', to which I insert the record.
create volatile table t1 as(
select date '1900-01-01' as date_col
)with data on commit preserve rows;
First procedure works fine, and insert the given date (2014-01-01).
replace procedure mi_table.dynamic_param()
begin
CALL DBC.SYSEXECSQL(
'insert into t1
select date '||'''2014-01-01'''||' ;'
);
end;
What I really want to do and doesn't work, is something as such:
replace procedure mi_table.dynamic_param() begin
declare max_avail_date date;
set max_avail_date = (select period_dt from db.table) ;
CALL DBC.SYSEXECSQL(
'insert into t1 select '||:max_avail_date||' ;'
);
end;
which doesn't work. It seems like what is returned from '(select period_dt from db.table)' is under 'yy/mm/dd' format. Thanks to the suggestions below, I came up with the following (non-elegant) solution:
Whenever I want to use max_avail_date, I use cast((cast('''||'20'||'''||'''||max_avail_date||''' as int)-19000000) as date) .
It does the job, but I'm sure there's a better way of doing it :)
edited 2014-09-27, 6:50pm