Fixed some SQL issue in facilities