fixed typos in queries.
fixed bug in sql string generation.