That error means that the data that your query was working with has
changed in the underlying tables. By using NOLOCK, you're allowing
other processes to change the same data that you're attempting to
perform aggregations on. I suspect you threw NOLOCK in there to "solve"
a performance problem (i.e. your query blocks everything else in the
system). Get rid of NOLOCK, and fix the query.
Is the code you posted the complete query? If so, WHY are you
calculating COUNT and MAX, stuffing those into a temp table, and then
never using those values? You could accomplish everything you have
written here with a single SELECT statement.