Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keep 2 Years Data - Account for Leap Year

Status
Not open for further replies.

saw15

Technical User
Jan 24, 2001
468
US
Working with a claims table, I want to keep the past two years claims based on the received date. I have come up with this and was wondering if this was the best approach? Or is there possibly a better approach? FYI, the entereddate is a datetime field.

SELECT * from claim
where dateadd(yyyy,-2,convert(varchar(10),getdate(),101))
> convert(varchar(10),entereddate,101)
order by entereddate

Help is appreciated.
 
If your entereddate field is datetime, why bother converting to varchar(10). That will just slow it down. Your logic is sound, just try:
Code:
SELECT * from claim
where dateadd(yyyy,-2,getdate()) > entereddate
order by entereddate

Now the question is what are you going to do with the data that you want to truncate out that is older than 2 years? Copy it to an archive? Delete it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top