Query build and error