Fixed some custom sql that was problematic between sql vendors.