private void tsbCopyUnionSubquery_Click(object sender, EventArgs e) { // add empty UnionSubQuery UnionSubQuery usq = queryBuilder1.ActiveUnionSubQuery.ParentGroup.Add(); // copy the content of existing union sub-query to a new one SQLSubQuerySelectExpression usqAst = queryBuilder1.ActiveUnionSubQuery.ResultQueryAST; usqAst.RestoreColumnPrefixRecursive(true); List <SQLWithClauseItem> lCte = new List <SQLWithClauseItem>(); List <SQLFromSource> lFromObj = new List <SQLFromSource>(); queryBuilder1.ActiveUnionSubQuery.GatherPrepareAndFixupContext(lCte, lFromObj, false); usqAst.PrepareAndFixupRecursive(lCte, lFromObj); usq.LoadFromAST(usqAst); queryBuilder1.ActiveUnionSubQuery = usq; }
private void LoadQueryWithUnions() { UnionSubQuery unionSubQuery = _query.QueryRoot.FirstSelect(); DataSource ds1 = _query.AddObject(unionSubQuery, "MyDB.MySchema.Customers"); // create output column QueryColumnListItem ci1 = unionSubQuery.QueryColumnList.AddField(ds1, "City"); ci1.Selected = true; UnionSubQuery union1 = unionSubQuery.ParentGroup.Add(); DataSource ds2 = _query.AddObject(union1, "MyDB.MySchema.Orders"); // create output column with grouping QueryColumnListItem ci2 = union1.QueryColumnList.AddField(ds2, "City"); ci2.Selected = true; ci2.Grouping = true; // Copy UnionSubQuery // add an empty UnionSubQuery UnionSubQuery usq = unionSubQuery.ParentGroup.Add(); // copy the content of existing union sub-query to a new one SQLSubQuerySelectExpression usqAst = unionSubQuery.ResultQueryAST; usqAst.RestoreColumnPrefixRecursive(true); List <SQLWithClauseItem> lCte = new List <SQLWithClauseItem>(); List <SQLFromSource> lFromObj = new List <SQLFromSource>(); unionSubQuery.GatherPrepareAndFixupContext(lCte, lFromObj, false); usqAst.PrepareAndFixupRecursive(lCte, lFromObj); usq.LoadFromAST(usqAst); QueryColumnListItem ci3 = usq.QueryColumnList.AddField(ds1, "CustomerAddress"); ci3.Selected = true; }