added conditional single query to adhoc API