tags:

views:

15

answers:

2

How can i write a query in DB2 for following thing:

The difference between current timestamp and a timestamp field in dB should be >=4 hours AND <= 24 hours

Some one suggested this but its not working.

select * from tableName where 
                 date <=  DATEADD([hour], -4, CURRENT_TIME) and 
                 date date >=  DATEADD([hour], -24, CURRENT_TIME)

But its not working.Its giving following error.

SQL0104N  An unexpected token "[hour]" was found following "ortdate <=  
DATEADD(".  Expected tokens may include:  "<func_arg_list>".  SQLSTATE=42601
A: 

Use just Hour instead of [hour]

select * from tableName where 
                 date <=  DATEADD(Hour, -4, CURRENT_TIME) and 
                 date date >=  DATEADD(Hour, -24, CURRENT_TIME)
Salil
I am still geting following error :SQL0206N "HOUR" is not valid in the context where it is used. SQLSTATE=42703
aks
i am using this query now select * from DB2ADMIN.SR where reportdate <= DATEADD(Hour, -4, CURRENT_TIME) and reportdate >= DATEADD(Hour, -24, CURRENT_TIME)
aks
@ask: I'm suprised that this query works, to my knowledge there is no DATEADD function in db2.
inflagranti
A: 
select * 
from   table t
where  t.tscolumn between current timestamp - 24 hours 
                      and current timestamp - 4 hours
inflagranti