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.
| Author |
Topic |
|
ann
Posting Yak Master
220 Posts |
Posted - 2008-10-04 : 16:05:18
|
| I want to do a date comparison based on days, and if the days are greater than x amount I want to delete that record:psuedo:if tableA,column1 somedate >= 15 then delete recordI don't know how to do this, I know how to do a select based on a daterange but not sure how to go about this. Can anyone help?Thanks |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-10-04 : 16:17:21
|
| Use DateDiff function. |
 |
|
|
ann
Posting Yak Master
220 Posts |
Posted - 2008-10-04 : 16:24:20
|
| ok - so I can do the datediff to see the difference in days:Select interval = DateDiff(day, DateAdded, GetDate())From TableAso how do I add the part that determines if the interval is greater than 15, then delete the record? |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-10-04 : 18:56:06
|
| delete--select *from tableA awhere datediff(day, a.<yourDateColumn>, getdate()) >= 15run the blue part first to make sure you are about to delete only the intended rows. When you are satisfied then run the entire thing. (the SELECT part is commented out)Be One with the OptimizerTG |
 |
|
|
ann
Posting Yak Master
220 Posts |
Posted - 2008-10-04 : 19:03:41
|
| THANK YOU!!I had crazy stuff I was trying with if statements, etc., - so glad you repliedThanks again |
 |
|
|
|
|
|