Hi
I have below code and i want that Total should be displayed at the End
SELECT T3."ShortName" AS "Vendor Code",(Select Max("CardName") from OCRD where "CardCode" = T3."ShortName") AS "Vendor Name",
T3."Debit", T3."Credit"
FROM "TEST"."OJDT" T2 INNER JOIN JDT1 T3 ON T2."TransId" = T3."TransId" WHERE
(T2."TransId" not IN (SELECT T0."StornoToTr" FROM OJDT T0 where T0."StornoToTr" is not NULL)) AND (T2."StornoToTr" is NULL)
AND (T3."ShortName"=:Vendor )
and T2."TaxDate">= TO_DATE(:FromDate) and T2."TaxDate"<= TO_DATE(:ToDate)
UNION ALL
SELECT T2."CardCode" AS "Vendor Code", T2."CardName" AS "Vendor Name", (T2."DocTotal") + (T2."DpmAmnt") + (T2."DpmVat"),0
FROM "TEST"."OINV" T2
WHERE T2."DocDate" >= TO_DATE(:FromDate) and T2."DocDate" <= TO_DATE(:ToDate)
AND (T2."CardCode"=:Vendor ) AND T2."CANCELED" not in ('Y','C')
UNION ALL
SELECT 'Total' AS "Vendor Code",
NULL AS "Vendor Name", SUM(T3."Debit"),0
FROM "TEST"."OJDT" T2 INNER JOIN JDT1 T3 ON T2."TransId" = T3."TransId" WHERE
(T2."TransId" not IN (SELECT T0."StornoToTr" FROM OJDT T0 where T0."StornoToTr" is not NULL)) AND (T2."StornoToTr" is NULL)
AND (T3."ShortName"=:Vendor )
and T2."TaxDate">= TO_DATE(:FromDate) and T2."TaxDate"<= TO_DATE(:ToDate)
Thanks
Jayraj ChhayaPosted Dec 27, 2024, 5:48 AM
Hello Ramco Ramco,
To display the total at the end of your SQL query, you can utilize the
UNION ALLoperator effectively. The provided SQL code already includes a section to calculate the total, but it needs to be positioned correctly to ensure it appears last in the result set.This structure ensures that the total row is appended at the end of the result set, providing a clear summary of the data.