refactor assert_sql query to reuse capture_sql

set assert_sql to reuse the capture_sql method from above
instead of repeating the code

in response to comments on issue #14546