Hi
In below code i am getting error Incorrect Syntax near Union
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
Jaimin ShethiyaPosted Jan 8, 2025, 2:01 AM
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
Ramco RamcoPosted Jan 7, 2025, 6:03 AM
Hi
It is not from a table i just want to pass values
Thanks
Sangeetha SPosted Jan 7, 2025, 5:45 AM
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;