Could somebody tell me why this logic is not working? I am trying to calculate quantity sold for previous month (do not have columns for PrevMoBegDate and PrevMoEndDate) but get zero for value.
sum(case when dbo.SalesDetail.DateSold between (dateadd(m,DATEDIFF(m,0, CYPriorMonth.BegMo)-1, 0)) and (dateadd(m,DATEDIFF(m,-1, CYPriorMonth.EndMo)-1, -1)) then dbo.SalesDetail.QuantitySold else 0 end)
When I use getdate() instead of CYPriorMonth.BegMO and CYPriorEndMO, the logic works fine and I get a value.
Thanks in advance!
samistl (BOB member since 2012-12-26)