Extract code for outputting result set