Each query and sub-query in the query is represented with the SubQuery object in Active Query Builder; The main query can be accessed via the QueryBuilder.SqlQuery.QueryRoot property.
Each sub-query may be either a single SELECT statement or a set of SELECT statements joined with the UNION, EXCEPT, INTERSECT and other keywords. Each single SELECT statement is represented via the UnionSubQuery object.
The UnionSubQuery object holds datasources, their links (UnionSubQuery.FromClause), expressions and criteria (UnionSubQuery.QueryColumnList) of the single SELECT statement.
There are few useful helpers you can use in your project:
  • The SubQuery.FirstSelect() method returns link to UnionSubQuery object representing the first single SELECT statement in the query.
  • The QueryBuilder.ActiveUnionSubQuery property gets the single SELECT statement currently visible to the end-user. The QueryBuilder.ActiveUnionSubQueryChanged event is fired when user switches to another statement.
The following code collects all SubQuery and UnionSubQuery objects in a query:
// collect all Sub-queries
var allSubQueries = queryBuilder1.SQLQuery.QueryRoot.GetChildrenRecursive<SubQuery>(true);

// insert the main Query to the beginning of the list
allSubQueries.Insert(0, queryBuilder1.SQLQuery.QueryRoot);

// collect all Union Sub-queries
var allUnionSubQueries = queryBuilder1.SQLQuery.QueryRoot.GetChildrenRecursive<UnionSubQuery>(true);
Each query and sub-query in the query is represented with the SubQuery object in Active Query Builder; The main query representation class Query is descendant of the SubQuery class. The main query can be accessed via the QueryBuilder.Query property. To get access to the list of sub-queries, use the QueryBuilder.SubQueries collection.
Each sub-query may be either a single SELECT statement or a set of SELECT statements joined with the UNION, EXCEPT, INTERSECT and other keywords. Each single SELECT statement is represented via the UnionSubQuery object.
There are few useful helpers you can use in your project:
  • The QueryBuilder.Query.FirstSelect() method returns the link to an object representing the first single SELECT statement in the query.
  • The QueryBuilder.ActiveSubQuery.ActiveUnionSubQuery property gets the single SELECT statement currently visible to the end-user. The QueryBuilder.ActiveUnionSubQueryChanged event is fired when user switches to another statement.
The UnionSubQuery object holds datasources, their links (UnionSubQuery.FromClause), expressions and criteria (UnionSubQuery.QueryColumnList) of the single SELECT statement.
The following code collects all SubQuery and UnionSubQuery objects in a query:
private void button1_Click(object sender, EventArgs e)
{
    var allSubQueries = queryBuilder1.SubQueries;

    var allUnionSubQueries = new List<UnionSubQuery>();
    foreach (var subQuery in allSubQueries)
    {
        subQuery.GatherUnionSubQueries(allUnionSubQueries);
    }
}
The Query Structure Demo project that is shipped among with the full and trial installation packages provides sample code of analyzing query structure and dumping it into text file.

Is this article helpful for you?