Monday, February 7, 2011

Query: Using groupby and order by when using sum()

Using groupby and order by when using sum()

Select sum(qtyOrdered) from SalesLine order by SalesLine.LineNum Desc group by salesLine.LineNum, salesLine.CustAccount

Note: the order of columns in "Order By" should be same as in "Group By" else it will not work.

In case of query, the addsortfield should be done before adding the addGroupByField fields
ds.ordermode(OrderMode:GroupBy) should not be used (using this will prevent the OrderBy from working but there is a draw back. The grid sorting will not work)


Datasource-> init() method

QueryBuildDataSource OperationsDs;

;

OperationsDs = this.query().dataSourceTable(tablenum(CAP_OperationsList));

OperationsDs.addSortField(fieldNum(CAP_OperationsList, CAP_ProfileReferenceGroupId),sortOrder::Ascending);

OperationsDs.addSortField(fieldNum(CAP_OperationsList, CAP_CutLength),sortOrder::Descending);

OperationsDs.addGroupByField(fieldnum(CAP_OperationsList, CAP_ProfileReferenceGroupId));

OperationsDs.addGroupByField(fieldnum(CAP_OperationsList, CutGroupId));

//OperationsDs.orderMode(OrderMode::GroupBy);

RePrint column headings in report

SalesQuotation report -> checkPrintLineHeader()
element.executeBodyColumnHeadings(tablenum(CustQuotationTrans));

Disable a footer section in report

if (element.page() != 1)
{
    element.disableSection(totals);
    element.disableSection(CAP_SalesResp);
}