fixed sql query creation for updates