CRM-13467 - generalizing select-clause building and appending temp table