mssql server scripts

olaayo
olaayo used Ask the Experts™
on
Please can some one please give me a Sprocs to
First to select count from table where date is < 7days and or where data > 70days
The if the data is more than 0 i also what to use the dateadd function
Then Delete data from a table where date is < 7days and or where data > 70days
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
let me get this clear
you want a script that deletes all the rows that are older than 7 days?
do you have a date column in each one of your tables?
does it always have the same name?
Commented:
I typed an answer with the code for the stored proc only to have it error and all disappear because you deleted the question...   I'm not sure why you deleted and recreated the same exact question, but I'm not retyping it.  Here's what's left in my copy-paste memory:

CREATE PROCEDURE dbo.NameIt
AS
SET NOCOUNT ON;

I'd use a date diff with embedded date add functions for the comparison.  Use the same comparison for the delete's WHERE clause.
Dateadd
http://msdn.microsoft.com/en-us/library/ms186819.aspx


Datediff
http://msdn.microsoft.com/en-us/library/ms189794.aspx
Delete
http://msdn.microsoft.com/en-us/library/ms189835.aspx

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial