Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 delete table contents

Author  Topic 

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-10-07 : 06:32:45
Hi all..
I have a table which contains details for 30 days ..
I want to keep last 7 days only ..Others must be deleted..
How to do this ?.

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-10-07 : 06:35:45
And the table looks like? There is some sort of timestamp column?

Read your question again and think

"I know nothing but the question. Can I solve it? NO"

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-10-07 : 06:36:12
How do your store the dates in the table & what is the format?

PBUH

Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-10-07 : 06:46:30
While inserting the values i used getdate() function to insert values in the table..
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-10-07 : 06:47:35
can u help me on this topic
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=151146
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-10-07 : 06:53:21
Please learn HOW TO ASK A QUESTION.

please read this.
http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx

Do you understand that we *can't* help you with the information you've given us. We *don't* know your table structure or the data so we *can't* tell you what to do.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-10-07 : 06:54:59
[code]
delete from yourtable where
dateadd(dd,DATEDIFF(dd,0,yourcolumn),0)not between
dateadd(dd,DATEDIFF(dd,0,getdate()),0)-7 and dateadd(dd,DATEDIFF(dd,0,getdate()),0)
[/code]

PBUH

Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-10-07 : 07:01:43
quote:
Originally posted by Sachin.Nand


delete from yourtable where
dateadd(dd,DATEDIFF(dd,0,yourcolumn),0)not between
dateadd(dd,DATEDIFF(dd,0,getdate()),0)-7 and dateadd(dd,DATEDIFF(dd,0,getdate()),0)


PBUH




Tnx for your help ...
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-10-07 : 07:13:57
quote:
Originally posted by Transact Charlie

Please learn HOW TO ASK A QUESTION.

please read this.
http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx

Do you understand that we *can't* help you with the information you've given us. We *don't* know your table structure or the data so we *can't* tell you what to do.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION




I think i gave all the details about my table..
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-10-07 : 08:03:26
No you didn't!

You said
quote:

Hi all..
I have a table which contains details for 30 days ..
I want to keep last 7 days only ..Others must be deleted..
How to do this ?.

and Sachin made a *guess* that you'd have some column to keep track of the date. You could have had *anything* in that table.

I'm sorry but you are simply bad at giving us information to base answers on which is why your other topics haven't been answered yet. You don't post table structures, you don't give sample data.....

You had enough posts now that you should be able to ask a proper question.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-10-07 : 08:21:03
@jafrywilson

Come on with 274 posts you need to atleast know how to post the question.Now just look at this

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=151146#594185

How can one understand what you want?It's like a guess work which you think we seem to enjoy.I totally agree with Charlie on this.It's urgency on your part not on ours.So please try to be more specific from next time.
If you can please post the sample o/p for the question you had in the link I posted above.

PBUH

Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-10-07 : 10:20:47
From the next time itself i will try my best to ask a question with full details ...Communication is my first disadvantage for this kind of problem problem ...I will try improve myself ..Thanks for the response...
Go to Top of Page
   

- Advertisement -