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 2000 Forums
 SQL Server Development (2000)
 report to for previous month

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-10-04 : 22:51:33
Tom writes "I have a query that I would like to run daily, but I want to pick up the first and last day of the previous month, ie if run on the 10th of October to pick up 1st of Sept and 30th of Sept.
I am finding it difficult as months do have different day in them.

I have a sample query below which is nearly there but is picking up the incorrect first date. Any help would be oblidged.

DECLARE @first datetime,
@last datetime


SELECT @first = DATEADD(month,-1,getdate())
SELECT @last = DATEADD(day,-1,DATEADD(month,1,@first))
SELECT 'Dates for Monthly period are : ' + CONVERT(varchar(12), @first, 106) + ', Until : ' + CONVERT(varchar(12), @last, 106)
print ' '
print ' '

I am using SQLSERVER 6.5 for this (Unfortunately.)"
   

- Advertisement -