Fixed some sql statements