try:
return (exec 'select isnull(max('+@id+'), 0)+1 from '+@table)