SQLTeam.com | Weblogs | Forums

Explain logic


#1

HI All,
Please can one explain below logic:
select @EndDate = DATEADD(DD,1,MonthEndDate)
FROM MonthDim WHERE MonthDimKey = convert(int, convert(varchar(6), (DATEADD (MM , -1 , GETDATE())), 112))

SELECT @startdate = MonthStartDate
FROM MonthDim WHERE MonthDimKey = convert(int, convert(varchar(6), (DATEADD (MM , -1 , GETDATE())), 112))

Thanks


#2

@sandy,
BOL says 112 = yyyymmdd, so convert to varchar(6) returns yyyymm

SELECT @EndDate = DATEADD(DD,1,MonthEndDate)  -- assign @enddate the value of 
FROM MonthDim                                 -- MonthEndDate + 1 month
WHERE 
   MonthDimKey = 
      Convert(int, Convert(varchar(6), (DateAdd (MM , -1 , GetDate())), 112)) -- 201611

#3

tnxs