Fix SQL bug with references/includes