Solved

Delete Records After 24H

Posted on 2011-03-22
3
506 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running total between 2 sql tables in Sql 6 45
encrypt SQL Server 2008 port 1433 3 41
section a string 5 53
Report 8 24
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

738 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