Hi,
I think the Last date can be font by
SELECT @r=dateadd(day,-(datepart(day,@d)),dateadd(mm,1,@d))
No need to use
SELECT @r=dateadd(day,-(datepart(day,dateadd(mm,1,@d))),dateadd(mm,1,@d))
Because, datepart(day,@d) and datepart(day,dateadd(mm,1,@d)) will return the same result. Then why...