updated code and generated sql query at one shot