Windows/MSSQL
지날달 가져오기
아로스
2010. 10. 21. 11:56
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