Active Query Builder support area

How to change aliases for query output columns programmatically?

Last modified:


The following example adds aliases for the fields of the main query in case an alternate name is defined for a field and its alias is empty.

UnionSubQuery unionSubQuery = queryBuilder1.SQLQuery.QueryRoot.FirstSelect();

unionSubQuery.BeginUpdate();

try
{
	for (int i = 0; i < unionSubQuery.QueryColumnList.Count; i++)
	{
		QueryColumnListItem ci = unionSubQuery.QueryColumnList[i];

		if (ci.ExpressionField != null) // the criteria item is bound to a metadata field
		{
			if (ci.AliasString.Length == 0 && ci.ExpressionField.AltName.Length > 0)
			{
				ci.AliasString = ci.ExpressionField.AltName;
			}
		}
	}
}
finally
{
	unionSubQuery.EndUpdate();
}

Is this article helpful for you?