I have table like this
create table tbl_1(
year int,
month int,
day int
)
insert into tbl_1 values(2009, 11, 30)
insert into tbl_1 values(2010, 3, 4)
insert into tbl_1 values(2011, 5, 13)
insert into tbl_1 values(20011, 12, 24)
I want to delete date from 2009-11-30 until 2011-5-13, but I can't because all of columns are int and I can't use this query :
delete from tbl_1
where year >=2009
and year<=2011
and month >=11
and month <=5
and day >=30
and day <=13
..because: 1 < month < 12 and 1 < day < 30
I know that this is terrible mistake.
I have many table that use this way for save date , please help me I don't have time to delete and recreate all of them.
You could do it like this:
DELETE FROM tbl_1
WHERE (year * 10000 + month * 100 + day) BETWEEN 20091130 AND 20110513
I haven't tested this. I would recommend testing it first on a test system before running it on your production data so that you don't accidentally delete the wrong data.
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