select quarter in table, DRY up code