Improve test; extract join SQL string to a local var