Hi
I have below code and i want that Total should be displayed at the End
SQL
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(:FromDate) and T2."DocDate" = TO_DATE(:FromDate) and T2."TaxDate"<= TO_DATE(:ToDate)Thanks

Jayraj ChhayaRank #304 · 8.2K reputationPosted Dec 27, 2024, 12:48 AM EST
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.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(:FromDate) AND T2."DocDate" = TO_DATE(:FromDate) AND T2."TaxDate" <= TO_DATE(:ToDate);This structure ensures that the total row is appended at the end of the result set, providing a clear summary of the data.