bjswift
May 18th, 2006, 03:52 PM
I have a data summary table, which has 2 columns I get to work with, year and month. Now, I need to truncate the table in a stored procedure for all of the data older than a certain date (lets just say 5 months from today's date).
I would like it to be a simple delete statement, with a where clause, but I can't say delete from TABLE where year <= datepart(yy,getdate()) and month <= datepart(mm, getdate())
because if the target delete tate was 4/2005 then everything will be deleted before 4/2005 except for 5/2004 6/2004 7/2004 8/2004 9/2004 10/2004 11/2004 12/2004...
Now, I thought about combining the date values, forming an integer such as 200504, which should work, but it is a lot of concatination... Guess getting the job done sometimes is getting it done cleverly.
Any suggestions?
I would like it to be a simple delete statement, with a where clause, but I can't say delete from TABLE where year <= datepart(yy,getdate()) and month <= datepart(mm, getdate())
because if the target delete tate was 4/2005 then everything will be deleted before 4/2005 except for 5/2004 6/2004 7/2004 8/2004 9/2004 10/2004 11/2004 12/2004...
Now, I thought about combining the date values, forming an integer such as 200504, which should work, but it is a lot of concatination... Guess getting the job done sometimes is getting it done cleverly.
Any suggestions?