Hi I have a table contains shopping cart info I want to delete the carts who are 15 day old I have a coloumn that I store date in that
how can I delete records each 15 day and can I do it dynamicly
Regards mahsTry:
delete MyTable
where
TheDate < getdate () - 15
--
Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"mahsa" <anonymous@.discussions.microsoft.com> wrote in message
news:6AF95014-D4BE-4064-8E18-7B3FB89FA3E7@.microsoft.com...
Hi I have a table contains shopping cart info I want to delete the carts who
are 15 day old I have a coloumn that I store date in that ,
how can I delete records each 15 day and can I do it dynamicly?
Regards mahsa|||Yes, write a stored procedure like this:
CREATE PROCEDURE dbo.clearCartData
AS
BEGIN
DELETE CartTable
WHERE [date column] < GETDATE()-15
END
GO
Then use SQL Agent to schedule the job to run once per day. (I assume you
want a rolling window, rather than delete a bunch of data every 15 days.)
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"mahsa" <anonymous@.discussions.microsoft.com> wrote in message
news:6AF95014-D4BE-4064-8E18-7B3FB89FA3E7@.microsoft.com...
> Hi I have a table contains shopping cart info I want to delete the carts
> who are 15 day old I have a coloumn that I store date in that ,
> how can I delete records each 15 day and can I do it dynamicly?
> Regards mahsa
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment