I see. Might I suggest a simple security add on.
Add this verification before using the variable as the tablename :
IF EXISTS (Select * from DBNAME.dbo.SysObjects where name = @TableName and uid = 1 and XType = 'U')
begin
exec query
else
throw error - possible injection attack.