I need to remove a group by statement from a QueybuildDataSource object. Is there any method to do this? (The opposite of addGroupByField).
Asked
Active
Viewed 3,599 times
5
-
1Finally solved making the reverse procedure with removing all group by from the datasource and adding them with a addGroupByField at runtime. – Artem Antonov Nov 16 '11 at 10:27
3 Answers
5
@Artem, I don't think you can do it from the QBDS level. I think you need to do it from query().clearGroupBy();
@ian_scho, users under 100 reputation can't answer their own questions for 4-8 hours after posting...that's probably why he didn't post as an answer.

Alex Kwitny
- 11,211
- 2
- 49
- 71
-
Ah ok Alex. I'd better vote up your answer to give you more credos/reputation :) Thx. – ian_scho Nov 17 '11 at 10:05
-
I appreciate it ian_scho. Makes it easier to post on these forums haha. – Alex Kwitny Nov 21 '11 at 22:05
0
Unfortunately, x++ does not have any method to remove one field from group by but by some tricks we can do that. I have written a method for removing group by field:
public void removeGroupByField(FieldID _fieldId, TableId _tableId, Query _query)
{
int i = 1;
QueryGroupByField qgbf;
QueryBuildDataSource qbdsOld, qbdsNew;
Query newQuery;
qbdsOld = _query.dataSourceTable(_tableId);
newQuery = new Query(_query);
qbdsNew = newQuery.dataSourceTable(_tableId);
newQuery.clearGroupBy();
for(i = 1 ; i<= _query.groupByFieldCount(); i++)
{
qgbf = _query.groupByField(i, qbdsOld);
if(qgbf.fieldID() != _fieldId)
{
qbdsNew.addGroupByField(qgbf.fieldID());
}
}
_query = newQuery;
}
And for better performance u can change this method to input container of field Id which u want to remove from group by.

Nastaran Hakimi
- 695
- 1
- 16
- 36
0
Have you tried?...
QueryBuildDataSource qbds = ????;
QueryBuildFieldList qbdsFL;
;
qbdsFL = qbds.fields();
qbdsFL.clearFieldList();
You can then add fields to be grouped programmatically. Mimmicking a Select Distinct clause for example.

ian_scho
- 5,906
- 9
- 35
- 51
-
This removes the select fields from the query but not a group by. – Artem Antonov Nov 15 '11 at 10:25
-
Solved making the reverse procedure with removing all group by from the datasource and adding them with a addGroupByField at runtime. – Artem Antonov Nov 15 '11 at 15:50
-