fixed a bug for sql