Il vous manque l'instruction from et l'instruction where ici :
while @i <= @cnt
begin
select @sql =
'select t.objectID, t.DocID as ' + field +
' into #tmp_auditlog_' + field +
' from #tmp_auditlog_subselection t where Details like ' + details FROM #tmp_auditlog_fields WHERE id = @i
exec sp_executesql @sql
select @i = @i + 1
end