Getting a subtotal from the query

Quite frequently someone will want to display either a subtotal or total within the query. It is possible in the following ways. This is not the complete list, but they are the most often used methods:

  • By Union ALL
  • By running total
  • By system

The last method is very simple. It is a SAP Business One internal function. You can get the column total under the query result window using Ctrl+Click on the column header if the column is a numeric value. The following screenshot shows you an example:

Getting a subtotal from the query

Case 4-T1: By Union ALL

A request to add a summary to the following query script:

SELECT T0.[DocNum] as 'SO No.', T0.[DocDate] as ...

Get Mastering SQL Queries for SAP Business One now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.