Dynamic Query Builder for output