469,610 Members | 1,554 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

T-SQL Help

I am not very good at SQL, much less T-SQL. Please forgive my
ignorance in this area.

Can someone supply me with the necessary T-SQL to perform the following
task:

1) I have a table called "dbo.Locks".
2) That table has a column titled Timestamp with a type of datetime.
3) I want to delete rows from the Locks table that have a datetime
value of more than 1 minute old.

For example

Table: Locks
ColumnA Timestamp
12345 3/20/2005 13:05:06
67890 3/20/2005 13:07:00

Suppose the current datetime when the T-SQL is run is 3/20/2005
13:07:30

When this T-SQL runs, I want to delete row 12345 because it's Timestamp
column value is over 1 minute old.

(Note: This T-SQL will be defined as a step in a job that is scheduled
to run every 30 seconds).

Thanks in advance
Wardell Castles

Jul 23 '05 #1
1 1489
Hi

Checkout dateadd in Books online e.g.

DELETE FROM dbo.Locks
WHERE [Timestamp] < DATEADD(ss,-60, getdate())

John
"wardellcastles" <wa************@hotmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
I am not very good at SQL, much less T-SQL. Please forgive my
ignorance in this area.

Can someone supply me with the necessary T-SQL to perform the following
task:

1) I have a table called "dbo.Locks".
2) That table has a column titled Timestamp with a type of datetime.
3) I want to delete rows from the Locks table that have a datetime
value of more than 1 minute old.

For example

Table: Locks
ColumnA Timestamp
12345 3/20/2005 13:05:06
67890 3/20/2005 13:07:00

Suppose the current datetime when the T-SQL is run is 3/20/2005
13:07:30

When this T-SQL runs, I want to delete row 12345 because it's Timestamp
column value is over 1 minute old.

(Note: This T-SQL will be defined as a step in a job that is scheduled
to run every 30 seconds).

Thanks in advance
Wardell Castles

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Steve | last post: by
2 posts views Thread by dynoweb | last post: by
1 post views Thread by Ernesto | last post: by
2 posts views Thread by martin_rendell | last post: by
16 posts views Thread by David Lozzi | last post: by
6 posts views Thread by Jayson | last post: by
7 posts views Thread by Filips Benoit | last post: by
3 posts views Thread by SQLJunkie | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.