Solved

Delete Records After 24H

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server / Update DB? 22 36
HTML <font style="color:red"> 9 30
SQLCMD Syntax 2 13
job schedule 8 17
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.‚Äč
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

839 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