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
Jaimin ShethiyaPosted Jan 4, 2025, 3:16 AM
Please refer below link for understanding the union and union all concepts.
https://www.c-sharpcorner.com/article/union-vs-union-all-in-sql-server/
Thanks
Jaimin ShethiyaPosted Jan 4, 2025, 3:11 AM
Hello Ramco,
You nedd to use UNION for unique records.
Please use below query.
Thanks
Ramco RamcoPosted Jan 4, 2025, 2:02 AM
Hi
I have data like below and i want Code,Name to be dispalyed only once.
Uttam ChaturvediPosted Jan 3, 2025, 5:36 PM
Not completely sure regrading your requirements however you can try to use UNION instead of "Union ALL" which returns only unique records