Checking your code, I found that you could make some improvements to it. But to help you, we'll need the definition of the webproxylog5 table and user_parser function. And some sample data will help as well.
Meanwhile, you can change your first lines to avoid additional variables.
'declare @rptmonth datetime
select @rptmonth = DATEADD(MM, DATEDIFF(MM,0,GETDATE()) - 1, 0)
'