Skip to Content
0
Jan 08, 2020 at 02:17 AM

query union select

115 Views

Buenas tardes, tengo una query de SQL y la estoy traduciendo a HANA pero me encuentro con una traba,

Los SELECT por separados funcionan OK pero al ponerlos todos juntos por medio de la sentencia UNION o UNION ALL me arroja error y no funciona.

Me podrán dar una mano? soy bastante nuevo con el tema de SQL y SQL HANA y aprendiendo de manera autodidacta.

Muchas gracias a todos, copio el script:

SELECT T0."DocNum", 'Efectivo' AS "Tipo", T0."DocDate" AS "Registro", T0."DocDueDate" AS "Vencimiento", T0."CashAcct", T0."CashSum", T0."CardCode" AS "Cliente", T0."CardName" AS "Nombre", T0."DocCurr" AS "Mon", T0."JrnlMemo" AS "Detalle", ' ' AS "Nro", ' ' AS "Endosable", ' ' AS "Interno" FROM ORCT T0 WHERE T0."CashSum" <> 0 AND T0."DocDate" >= '[%1]' AND T0."DocDate" <= '[%2]' UNION SELECT T0."DocNum", 'Transferencias' AS "Tipo", T0."DocDate" AS "Registro", T0."DocDueDate" AS "Vencimiento", T0."TrsfrAcct", T0."TrsfrSum", T0."CardCode" AS "Cliente", T0."CardName" AS "Nombre", T0."DocCurr" AS "Mon", T0."JrnlMemo" AS "Detalle" FROM ORCT T0 WHERE T0."TrsfrSum" <> 0 AND T0."DocDate" >= '[%1]' AND T0."DocDate" <= '[%2]' UNION SELECT T1."DocNum", 'Cheques' AS "Tipo", T2."DocDate" AS "Registro", T1."DueDate" AS "Vencimiento", T1."CheckAct", T1."CheckSum", T2."CardCode" AS "Cliente", T2."CardName" AS "Nombre", T2."DocCurr" AS "Mon", T4."BankName" AS "Detalle", CAST(T1."CheckNum" AS char(8)) AS "Nro", T1."Trnsfrable" AS "Endosable", T1."CheckAbs" AS "Interno" FROM RCT1 T1 LEFT OUTER JOIN ODSC T4 ON T1."BankCode" = T4."BankCode" LEFT OUTER JOIN ORCT T2 ON T1."DocNum" = T2."DocNum" WHERE T2."DocDate" >= '[%1]' AND T2."DocDate" <= '[%2]' UNION SELECT T0."DocNum", 'Retenciones' AS "Tipo", T0."DocDate" AS "Registro", T2."DueDate" AS "Vencimiento", T6."Account", T2."SumPercpAm", T0."CardCode" AS "Cliente", T0."CardName" AS "Nombre", T0."DocCurr" AS "Mon", T6."WTName" AS "Detalle", CAST(T2."RefNumber" AS char(8)) AS "Nro", ' ' AS "Endosable", ' ' AS "Interno" FROM OWTC T2 INNER JOIN WTC1 T5 ON T2."AbsEntry" = T5."AbsEntry" INNER JOIN OWTD T6 ON T5."WtAbsEntry" = T6."AbsEntry" INNER JOIN ORCT T0 ON T0."DocNum" = T2."RctAbs" WHERE T2."RctType" = '24' AND T0."DocDate" >= '[%1]' AND T0."DocDate" <= '[%2]';