Ramco Ramco

Ramco Ramco

  • 435
  • 3.4k
  • 553.7k

Code & Name to be displayed only once.

Jan 3 2025 3:26 PM

Hi

  In below code i want Vendor Code and name to be displayed only once

INSERT INTO TempTable ("Vendor Code", "Vendor Name", "BPLName", "Document No", "TaxDate", "Document Type", "Debit Amount", "Credit Amount")
SELECT
    T3."ShortName" AS "Vendor Code",
    (SELECT MAX("CardName") FROM OCRD WHERE "CardCode" = T3."ShortName") AS "Vendor Name",
    T3."BPLName",
    T2."BaseRef" AS "Document No",
    T2."TaxDate" AS "TaxDate",
    CASE
        WHEN T3."TransType" = '204' THEN 'A/P Down Payment Invoice'
        WHEN T3."TransType" = '46' THEN 'Outgoing Payment'
        WHEN T3."TransType" = '18' THEN 'A/P Invoice'
        ELSE ' '
    END AS "Document Type",
    T3."Debit" AS "Debit Amount",
    T3."Credit" AS "Credit Amount"
FROM
    "OJDT" T2
INNER JOIN
    "JDT1" T3 ON T2."TransId" = T3."TransId"
WHERE
    T3."ShortName" = :BpCode

UNION ALL

SELECT
    T2."CardCode" AS "Vendor Code",
    T2."CardName" AS "Vendor Name",
    T2."BPLName" AS "BPLName",
    T2."DocNum" AS "Document No",
    T2."DocDate" AS "TaxDate",
    'A/P Invoice' AS "Document Type",
    0 AS "Debit Amount",
    (T2."DocTotal" + T2."DpmAmnt" + T2."DpmVat") AS "Credit Amount"
FROM
    "OPCH" T2
WHERE
    T2."DocDate" BETWEEN TO_DATE(:FromDate, 'YYYY-MM-DD') AND TO_DATE(:ToDate, 'YYYY-MM-DD')
    AND T2."CardCode" = :BpCode
    AND T2."CANCELED" NOT IN ('Y', 'C');

Thanks


Answers (4)