Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I have two tables, one that acts as an event log for another software, and the other is simply a table that I want to use for roll-off. The event log table gets very large very fast, so what I'm trying to do is setup a script that runs every night that will take any data that is older than three days and transfer it to this "roll-off" table.The problem is as follows:The event log table keeps time with a Unix time stamp. To deal with this I created this bit of code that seemed like it would be a quick and easy solution:alter table TABLE1add SQL_Time datetime;goupdate TABLE1 set sql_time = dateadd(ss,time_stamp,'19700101');goinsert into TABLE2select *from TABLE1where sql_time <= getdate() - 3;goDelete from TABLE1where sql_time <= getdate() - 3;goRight after I add the column titled "SQL_Time" the event log table stops recording the events from the software that it is connected to, and therefore make the table worthless.My question:How can I turn the Unix Time Stamp column into something that SQL can read and perform the function that I have outlined above?
RickD
Slow But Sure Yak Herding Master
3608 Posts
Posted - 2009-03-24 : 11:24:11
You could do it without adding a column:
insert into TABLE2select *from TABLE1where dateadd(ss,time_stamp,'19700101') <= getdate() - 3;goDelete from TABLE1where dateadd(ss,time_stamp,'19700101') <= getdate() - 3;go