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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to delete all rows but noon's on Friday?

Author  Topic 

ostinoh
Yak Posting Veteran

66 Posts

Posted - 2011-12-02 : 13:28:01
Hello -

I need help in creating a store procedure that will clean out a table that has been having data inserted into it all day every 2 hours. The one thing is I need is to keep Friday's Noon run for archival purposes.

In this table is a point in time column I can referance that shows the current date and time the SSIS package ran to pull in the data into the table.

I've looked and tried many scipts but cannot get anything to work. Can someone help me out?

Thanks
David

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-12-02 : 13:34:23
delete tbl
where (datename(dw,dte)<>'Friday' or datepart(hh,dte) <> 12)

that should delete everything that was not inserted between 12:00 and 1:00 on friday.
Depends on what your datetime column contains and how long the midday run takes. Might want datepart(hh,dte) not in (12,13).

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

ostinoh
Yak Posting Veteran

66 Posts

Posted - 2011-12-02 : 13:52:28
My datetime column looks like this 2011-12-02 09:40:00. Can you add mintues to the script as well?

It takes about 15 minutes for the whole thing to run.

Thanks
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-12-02 : 13:56:18
No need as it runs every 2 hours just omit things between 12 and 1

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

ostinoh
Yak Posting Veteran

66 Posts

Posted - 2011-12-02 : 13:59:45
Thank you I tired it and that worked like a charm. I was wondering how would I add in the minutes because I'm on the east coast noon as come and gone and I would like to test this with out having to wait until next Friday.
Go to Top of Page
   

- Advertisement -