set @SQL =N'select name,count(id) as count from '+@TableName+' group by name having count(id)>1 '
 DECLARE cur_repeat CURSOR FOR   
 Exec( @SQL ) 
=====>
 set @SQL =N'select name,count(id) as count from '+@TableName+' group by name having count(id)>1 '
 Exec('DECLARE cur_repeat CURSOR FOR   '+ @SQL )