Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why using LIKE with TIMESTAMPS do not work in DB2

i have problem using LIKE structure in DB2: for example:

select * from TEST where TIME LIKE '2012-03-04-%'

FYI. - TIME is TIMESTAMP data type.

why using LIKE with TIMESTAMPS do not work?

Additional info: i want to extract data from one single day provided by user in select statement.

like image 263
f00sa Avatar asked Apr 04 '12 10:04

f00sa


1 Answers

Just expanding on @mortb's answer, I'd either use BETWEEN or

WHERE time >= '2012-03-04' AND time < '2012-03-05'

The advantage of using BETWEEN or a comparison that using casts and LIKE will mean that if there is an index on time it wouldn't be able to be used due to the casting.

like image 174
beny23 Avatar answered Nov 15 '22 04:11

beny23