Solved

Delete Records After 24H

Posted on 2011-03-22
3
482 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

762 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

18 Experts available now in Live!

Get 1:1 Help Now