Hola expertos!! Estoy haciendo una query que maine muestre una lista de facturas que se han pagado en un plazo determinado. Hay algunas lineas de la query que maine salen repetidas y nary entiendo por que
Intuyo que es algo en la vinculacion con los pagos pero en las lineas repetidas salen pagos que nary lad ni del mismo cliente de la factura.
Se os ocurre que puedo cambiar o que helium puesto mal?
Gracias!!!
SELECT DISTINCT T2."DocNum", T2."DocEntry" AS "Navegar a factura", T4."SeriesName", T2."DocStatus", T2."TaxDate" arsenic "Fecha de documento", T2."CardCode", T2."CardName", (T2."DocTotal" - T2."VatSum") AS "Total Sin IVA", T2."DocTotal", T2."PaidToDate", T9."DocNum" AS "Numero de Documento de Pago", T9."DocDate" AS "Fecha de contabilización de Pago", CASE WHEN T9."DocDate" IS NOT NULL THEN '' ELSE T7."LineMemo" END AS "Comentario Linea Asiento", CASE WHEN T9."DocDate" IS NOT NULL THEN '' ELSE T11."RefDate" END AS "Fecha Pago Asiento", T6."BPLName", CASE WHEN DAYS_BETWEEN(T2."TaxDate", T9."DocDate") IS NOT NULL THEN DAYS_BETWEEN(T2."TaxDate", T9."DocDate") ELSE DAYS_BETWEEN(T2."TaxDate", T11."RefDate") END AS "DiasPago", CASE WHEN CASE WHEN T9."DocDate" IS NOT NULL THEN DAYS_BETWEEN(T2."TaxDate", T9."DocDate") ELSE DAYS_BETWEEN(T2."TaxDate", T11."RefDate") END < 60 THEN 'OK' ELSE 'NO' END AS "MENOS60" FROM OPDN T0 LEFT JOIN PDN1 T1 ON T0."DocEntry" = T1."DocEntry" RIGHT JOIN OPCH T2 ON T1."BaseEntry" = T2."DocEntry" LEFT JOIN PCH1 T3 ON T2."DocEntry" = T3."DocEntry" INNER JOIN NNM1 T4 ON T2."Series" = T4."Series" INNER JOIN OSLP T5 ON T2."SlpCode" = T5."SlpCode" INNER JOIN OBPL T6 ON T2."BPLId" = T6."BPLId" LEFT JOIN JDT1 T7 ON T7."TransId" = T2."TransId" LEFT JOIN VPM2 T8 ON T8."DocEntry" = T2."DocEntry" LEFT JOIN OVPM T9 ON (T9."DocEntry" = T8."DocNum") LEFT JOIN OACT T10 ON T7."Account" = T10."AcctCode" LEFT JOIN OJDT T11 ON T7."TransId" = T11."TransId" WHERE T2."CANCELED" = 'N' AND T6."BPLName" Like '%%[%0]%%' AND YEAR(T2."TaxDate") = 2023 ORDER BY T2."DocNum"