declare @targetdate datetime,
@targetdate_lastmonth1 datetime,
@targetdate_lastmonth2 datetime
select @targetdate = getdate()
select @targetdate_lastmonth1 = dateadd(month,1,dateadd(m,-1,@targetdate) )-(day(@targetdate))
select @targetdate_lastmonth2 = dateadd(month,1,dateadd(m,-2,@targetdate) )-(day(@targetdate))
select @targetdate, @targetdate_lastmonth1, @targetdate_lastmonth2
@targetdate_lastmonth1 datetime,
@targetdate_lastmonth2 datetime
select @targetdate = getdate()
select @targetdate_lastmonth1 = dateadd(month,1,dateadd(m,-1,@targetdate) )-(day(@targetdate))
select @targetdate_lastmonth2 = dateadd(month,1,dateadd(m,-2,@targetdate) )-(day(@targetdate))
select @targetdate, @targetdate_lastmonth1, @targetdate_lastmonth2