Buenas tardes estimados!!
Tema : MODULO PRODUCCION
Tengo este query. La primera columna es el numero del documento de la ORDEN DE PRODUCCION
El query tiene 2 query unidos por el union all.
La Parte uno del query si lo ejecuto individualmente en el generador de consultas del SAP B1 me muestra me muestra el enlace al DocNum de la ORDEN DE PRODUCCION.
Si ejecuto todo el query, incluyendo parte uno y parte dos. NO MUESTRA el enlace.
Simplificando para que me puedan entender mejor.
Ejecutando parte uno o parte dos unicamente, muestra los enlaces.
Si ejecuto con el union all NO MUESTRA el enlace.
¿ Alguien me podria esplicar el motivo?
El query lo realizo para cruzar las EMISIONES DE PRODUCCION con los RECIBOS DE PRODUCCION.
– Parte uno
select "DocNum",
SUM("Planeado"), SUM("Recibido"), SUM("Emision"), SUM("Sueldo"), SUM("Aporte"), SUM("AGUINALDO"), count(*) as "Repe"
from
(
SELECT
t2."DocNum",
t0."DocEntry",
(select sum(t11."PlannedQty") from owor t11 where t11."DocNum" = t0."BaseRef" group by t11."DocNum") as "Planeado",
(select sum(t10."Quantity") from ign1 t10 where t10."BaseRef" = t0."BaseRef" group by t10."BaseRef") as "Recibido",
(t0."Quantity"* t0."Price") as "Emision",
round( (t0."Quantity"* t0."Price") * 80.1064 / 100 , 0) as "Sueldo",
round( (t0."Quantity"* t0."Price") * 13.2176 / 100 ,0) as "Aporte",
ROUND( (t0."Quantity"* t0."Price") * 6.6756 / 100,0) AS "AGUINALDO"
FROM IGE1 t0
INNER JOIN ORSC T1 ON t0."ItemCode" = T1."VisResCode"
INNER JOIN OWOR T2 ON T0."BaseRef" = t2."DocNum"
WHERE T0."DocDate" between '20231023' and '20231030'
) x
GROUP BY x."DocNum"
having count(*) = 1
union all
-- Parte dos
select "DocNum",
SUM("Planeado"), SUM("Recibido"), SUM("Emision"), SUM("Sueldo"), SUM("Aporte"), SUM("AGUINALDO"), count(*) as "Repe"
from
(
SELECT
t2."DocNum",
t0."DocEntry",
(select sum(t11."PlannedQty") from owor t11 where t11."DocNum" = t0."BaseRef" group by t11."DocNum") as "Planeado",
(select sum(t10."Quantity") from ign1 t10 where t10."BaseRef" = t0."BaseRef" group by t10."BaseRef") as "Recibido",
(t0."Quantity"* t0."Price") as "Emision",
round( (t0."Quantity"* t0."Price") * 80.1064 / 100 , 0) as "Sueldo",
round( (t0."Quantity"* t0."Price") * 13.2176 / 100 ,0) as "Aporte",
ROUND( (t0."Quantity"* t0."Price") * 6.6756 / 100,0) AS "AGUINALDO"
FROM IGE1 t0
INNER JOIN ORSC T1 ON t0."ItemCode" = T1."VisResCode"
INNER JOIN OWOR T2 ON T0."BaseRef" = t2."DocNum"
WHERE T0."DocDate" between '20231023' and '20231030'
) x
GROUP BY x."DocNum"
having count(*) > 1