I just tried it again on my 2005 instance. Works fine for me but I do get that error if I don't have the following declare at the top.
DECLARE
@TABLENM SYSNAME,
@CNT INT,
@TOPN INT
It can be tricky doing the copy and paste thing. I know because it has happened to me a lot.
ATBCharles Kincaid