sql query generation from statements