Changed to use temp table instead of union to resolve SQL memory error when running