Need help in writing the query to get the last month data as well as month to date data.
If today\'s date is Mar 23 2011, I need to retrieve the data from last month
Very helpful page
declare @d datetime = '2011-04-03'; declare @startDate datetime; select @startDate = CAST('01 '+ RIGHT(CONVERT(CHAR(11),DATEADD(MONTH,-1,@d),113),8) AS datetime); select @startDate;