• You cannot do this:

    [font="Courier New"]SELECT @Rows = COUNT(*) FROM @tblname[/font]

    To do this, @tblname would have to be a table variable. In your case, it is a varchar that represents the name of the table you want to count. To do this, you need to use dynamic SQL (EXEC() or sp_execute_SQL).