Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find records added for the previous month

Status
Not open for further replies.

cocopud

Technical User
Jan 8, 2002
139
US
I have the following SELECT statement that I am using in SQL Server 2000 that selects additions during a certain timeframe

SELECT *
FROM Facilities
WHERE (approve_datetime BETWEEN '2009-08-01' AND '2009-08-07') AND (action = 'A')

I would like to create a stored procedure on the 1st of every month that would create a file with this information for the previous month. Is there a way to do this so that every month I get the previous months data? (Additionally, if this can be done would the logic be any different if I wanted to run it every sunday for the previous weeks data?)
 
I have played with this and if I use DATEDIFF, I can get it to return the data I need,
WHERE DATEDIFF(m, wf_approve2_datetime, GETDATE()) = 1

but if I add in the AND action = 'A' , I get no data.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top