Hi
In below code i am getting error Incorrect Syntax near Union
SQL
SELECT v_opgDebit,v_opgCredit,'' AS "CardCode",'' AS "CardName",'' As "Branch", '' AS "DocNo", '' as "DocDate",
'' as "Remarks",v_opgDebit As "Debit", v_opgCredit As "Credit"
Union All
SELECT v_opgDebit,v_opgCredit,T3."ShortName" AS "CardCode",(Select Max("CardName") from OCRD where "CardCode" = T3."ShortName") AS "CardName",T3."BPLName" As "Branch", T2."BaseRef" AS "DocNo", T2."TaxDate" as "DocDate",
T3."LineMemo" as "Remarks",T3."Debit" As "Debit", T3."Credit" As "Credit"
FROM "OJDT" T2 INNER JOIN JDT1 T3 ON T2."TransId" = T3."TransId" WHERE
(T3."ShortName"=:BpCode)
)Thanks

Sangeetha SRank #212 · 11.4K reputationPosted Jan 7, 2025, 12:45 AM EST
Ensure Each Select Statement Has the Same Number of Columns: Both SELECT statements must return the same number of columns with compatible data types.
Check for Spaces: Ensure there's a space before UNION ALL.
Parentheses: Make sure that any conditions in your WHERE clause are properly formatted.
Here’s a revised version of your query:
SELECT
v_opgDebit,
v_opgCredit,
'' AS "CardCode",
'' AS "CardName",
'' AS "Branch",
'' AS "DocNo",
'' AS "DocDate",
'' AS "Remarks",
v_opgDebit AS "Debit",
v_opgCredit AS "Credit"
FROM
DUAL -- or the appropriate table you are selecting from for the first SELECT
UNION ALL
SELECT
v_opgDebit,
v_opgCredit,
T3."ShortName" AS "CardCode",
(SELECT MAX("CardName") FROM OCRD WHERE "CardCode" = T3."ShortName") AS "CardName",
T3."BPLName" AS "Branch",
T2."BaseRef" AS "DocNo",
T2."TaxDate" AS "DocDate",
T3."LineMemo" AS "Remarks",
T3."Debit" AS "Debit",
T3."Credit" AS "Credit"
FROM
"OJDT" T2
INNER JOIN
JDT1 T3 ON T2."TransId" = T3."TransId"
WHERE
T3."ShortName" = :BpCode;
Ramco RamcoRank #462 · 5.4K reputationPosted Jan 7, 2025, 1:03 AM EST
Hi
It is not from a table i just want to pass values
Thanks
Jaimin ShethiyaRank #177 · 13.7K reputationPosted Jan 7, 2025, 9:01 PM EST
Hello Ramco,
In your first query i see the from statement is not there and you are used the other field name (v_opgDebit, v_opgCredit), so is that a only static values or that is belongs to the any other table.
If all values are static never changed, then instead of adding in sql, you can add one record from the C# itself, if possible.
Thanks