Link to home
Start Free TrialLog in
Avatar of csshahie
csshahie

asked on

Dynamic Query to pull records for the previous month

Hi

SQLServer2000 connection.Can anybody assist with the following:

A query that will automatically extract data for the previous month. I used this previously in MSAccess "Between DateSerial(Year(Date()),Month(Date())-1,1) And DateSerial(Year(Date()),Month(Date()),1)".This prevented me from using date prompts i.e I could run a macro in MSAccess with the above customised as a criteria.I am currently using a Business Intelligence tool

Thanks  
ASKER CERTIFIED SOLUTION
Avatar of adathelad
adathelad
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
DECLARE @dt SMALLDATETIME, @dt2 SMALLDATETIME

SET @dt = GETDATE() --NOW
SET @dt2 = DATEADD(MONTH,-1,@dt)

WHERE <field_name> BETWEEN @dt2 AND @dt

Avatar of CleanupPing
CleanupPing

csshahie:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.  

I will leave the following recommendation for this question in the Cleanup topic area:

Accept Answer From adathelad

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Arbert
EE Cleanup Volunteer