SELECT EDO.IDMAEEDO,EDO.TIDO,EDO.SUBTIDO,EDO.NUDO,EDO.ENDO,EDO.SUENDO,EDO.TIGEDO,EDO.SUDO,EDO.LUVTDO,EDO.FEEMDO,EDO.KOFUDO,EDO.ESDO,EDO.ESPGDO,EDO.CAPRCO,EDO.CAPRAD,EDO.CAPREX,EDO.CAPRNC,EDO.MEARDO,EDO.MODO,EDO.TIMODO,EDO.TAMODO,EDO.NUCTAP,EDO.VACTDTNEDO,EDO.VACTDTBRDO,EDO.NUIVDO,EDO.POIVDO,EDO.VAIVDO,EDO.NUIMDO,EDO.VAIMDO,EDO.VANEDO,EDO.VABRDO,EDO.POPIDO,EDO.VAPIDO,EDO.FE01VEDO,EDO.FEULVEDO,EDO.NUVEDO,EDO.VAABDO,EDO.MARCA,EDO.FEER,EDO.NUTRANSMI,EDO.TRANSMASI,(SELECT TOP 1 NUMECOM  FROM CCOMPRD1 AS D1 WITH ( NOLOCK )  INNER JOIN CCOMPRD AS D WITH ( NOLOCK ) ON D.IDCOMPRD=D1.IDCOMPRD  INNER JOIN CCOMPRE AS E WITH ( NOLOCK ) ON E.IDCOMPRE=E.IDCOMPRE  WHERE D1.IDRST=EDO.IDMAEEDO  AND D1.ARCHIRST='MAEEDO' ) AS NUCOCO,EDO.KOTU,EDO.LIBRO,EDO.LCLV,EDO.ESFADO,EDO.KOTRPCVH,EDO.NULICO,EDO.PERIODO,EDO.NUDONODEFI,EDO.TRANSMASI,EDO.POIVARET,EDO.VADEIVDO,EDO.VAIVARET,EDO.RESUMEN,EDO.TIDOELEC,EN.LVEN,EN.CRSD,EN.CRCH,EN.RTEN,EN.NOKOEN,EN.PAEN,( SELECT SUM(CASE WHEN (     DDO.POIVLI=0.0  AND DDO.VAIVLI=0.0  AND DDO.VANELI>0.0  AND DDO.LILG NOT IN ('CR','IM')) THEN DDO.VANELI*(CASE WHEN DDO.VANELI<0 THEN -1 ELSE 1 END)  ELSE 0.0 END )  FROM MAEDDO AS DDO WITH ( NOLOCK )  WHERE EDO.IDMAEEDO=DDO.IDMAEEDO ) AS EXENTO,(CASE WHEN EDO.SUBTIDO IN ('TJV','TJP') AND EDO.TIDO IN ('BSV','BLV','BLX')  THEN (SELECT SUM(COALESCE(D.VAASDP,0))  FROM MAEDPCD AS D WITH (NOLOCK)  INNER JOIN MAEDPCE AS E WITH ( NOLOCK ) ON E.IDMAEDPCE=D.IDMAEDPCE  WHERE D.IDRST=EDO.IDMAEEDO  AND D.ARCHIRST='MAEEDO'  AND E.TIDP='TJV' )  ELSE 0   END) AS TARJETA,(CASE WHEN EDO.SUBTIDO IN ('TJV','TJP') AND EDO.TIDO IN ('BSV','BLV','BLX')  THEN COALESCE((SELECT DISTINCT COUNT(CUDP+NUCUDP)  FROM MAEDPCD AS D WITH (NOLOCK)  INNER JOIN MAEDPCE AS E WITH ( NOLOCK ) ON E.IDMAEDPCE=D.IDMAEDPCE  WHERE D.IDRST=EDO.IDMAEEDO  AND D.ARCHIRST='MAEEDO'  AND E.TIDP='TJV' ),0)  ELSE 0   END) AS CASOSTJV  FROM MAEEDO AS EDO WITH ( NOLOCK )  LEFT JOIN MAEEN AS EN WITH ( NOLOCK ) ON EN.KOEN=EDO.ENDO AND EN.SUEN=EDO.SUENDO  WHERE EDO.EMPRESA='01'  AND EDO.TIDO IN ('BLV','BLX','BSV','FCL','FCV','FDB','FDV','FDX','FDZ','FEE','FEV','FVL','FVT','FVX','FVZ','FXV','FYV','NCB','NCV','NCX','NCZ','NEV') AND EDO.FEEMDO BETWEEN {d '2018-09-01'} AND {d '2018-09-30'} AND EDO.NUDONODEFI=0 