Test SQL query generation