I know the following can be done in db2:
select * from table where created_date < current_timestamp - 5 days;
but what is the correct syntax to do something like the following?
begin
declare numdays int default 5;
-- some logic
select * from table where created_date < current_timestamp - numdays days;
end;
The variables can be directly used in place of a constant as seen below:
create table test (dt timestamp);
begin
declare numdays int;
set numdays = 10;
insert into test
SELECT CURRENT_timestamp + numdays DAYS FROM sysibm.sysdummy1;
end ;
select current_timestamp, dt from test;
Returns
2017-12-14 08:20:39.19063 2017-12-24 08:20:35.503779
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With