ColdFusion – queryOfqueries union – elegant

private any function combineQuery(qA, qB) {
 var qry1Result = arguments.qA;
 var qry2Result = arguments.qB;
 var qoqResult = '';

// create new query object
 var qoq = new Query();

// set attribute of new query object to be a query result with arbortrary name

qoq.setAttributes(QoQsrcTableA = qry1Result);
 qoq.setAttributes(QoQsrcTableB = qry2Result);

// use previously set attribute as table name for QoQ andset dbtype = query
 qoqResult = qoq.execute(sql="select * from QoQsrcTableA union select * from QoQsrcTableB", dbtype="query");

// return result
 return qoqResult.getResult();

}

source: https://coldfusion.adobe.com/2017/10/unioning-queries-using-query-of-query/


Comments are closed.