text: USE NBNREPORTING
  GO
  
  SELECT
    MIN(CASE WHEN [TAXON COMMON NAME] = [TAXON LATIN NAME] THEN
      [TAXON GROUP]
    ELSE
      [TAXON COMMON NAME]
    END) AS [COMMON NAME],
    [TAXON LATIN NAME],
    [TAXON GROUP],
    MIN(SAMPLE_VAGUE_DATE_START) AS [FIRST RECORDED],
    MAX(SAMPLE_VAGUE_DATE_END) AS [LAST RECORDED],
    COUNT(OCCURRENCE_KEY) AS COUNT,
    [RECOMMENDED TAXON SORT ORDER],
    MIN(LIST_ITEM_KEY) AS [LIST ITEM KEY]
  INTO
    #HW_TEMP
  FROM
    HW_ALL
  WHERE
    [TAXON GROUP] IS NOT NULL AND
    [TAXON GROUP] != 'bird' AND
    [SAMPLE_VAGUE_DATE_TYPE] != 'U'
  GROUP BY 
    [TAXON LATIN NAME], [TAXON GROUP], [RECOMMENDED TAXON SORT ORDER]
  ORDER BY
    [RECOMMENDED TAXON SORT ORDER]
  GO
  
  SELECT
    [LIST ITEM KEY],
    [COMMON NAME],
    [TAXON LATIN NAME],
    [TAXON GROUP],
    NBNData.dbo.LCReturnDateShort([FIRST RECORDED],'D','F') AS [FIRST RECORDED],
    NBNData.dbo.LCReturnDateShort([LAST RECORDED], 'D', 'F') AS [LAST RECORDED],
    [COUNT]
  FROM
    #HW_TEMP
  GO
  
  DROP TABLE #HW_TEMP
  GO
  