Solved

Delete Records After 24H

Posted on 2011-03-22
3
488 Views
Last Modified: 2012-05-11
Hello Experts,

I have a MSSQL 2008 DB, with a varchar field that has a value like 3/21/2011 1:19:33 PM On this field i'm also able to use convert(datetime, fldPostedDateTime, 101).

My question is, with this info, how can i add a WHERE clause to check if 24 hours have past?

Thanks.
0
Comment
Question by:APD_Toronto
3 Comments
 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 250 total points
ID: 35192235
delete t
from tablename t
where datefield < dateadd(hour, -24, getdate())
0
 
LVL 11

Accepted Solution

by:
Larissa T earned 250 total points
ID: 35194805

run select first just to be safe :-)
delete t
--select *
from tablename t
where convert(datetime, fldPostedDateTime)< dateadd(hour, -24, getdate())
0
 

Author Closing Comment

by:APD_Toronto
ID: 35195310
thanks both
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now