I'm not spending half my day trying to debug this but at first glance I think there is something fishy about this part:( SOP10100.DOCDATE >= @fromdate AND SOP10100.DOCDATE < @todateOR SOP10100.DOCDATE >= @CurrMonthStart AND SOP10100.DOCDATE < DATEADD(MONTH, 1, @CurrMonthStart))
You need brackets around any expression that involves OR, if you don't the the logic in the expression will be hard to track. Change it to this:( (SOP10100.DOCDATE >= @fromdate AND SOP10100.DOCDATE < @todate)OR (SOP10100.DOCDATE >= @CurrMonthStart AND SOP10100.DOCDATE < DATEADD(MONTH, 1, @CurrMonthStart)))
and maybe you'll be better off.- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com