5

I need to remove a group by statement from a QueybuildDataSource object. Is there any method to do this? (The opposite of addGroupByField).

Artem Antonov
  • 109
  • 1
  • 6
  • 1
    Finally 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 Answers3

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
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