0% found this document useful (0 votes)
20 views1 page

Prueba

The document contains a long SQL query that selects data from various tables and joins them together. The query filters for data from a specific year, month, and document type where the document amount is greater than the amount paid according to other tables.

Uploaded by

Jezuz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

Prueba

The document contains a long SQL query that selects data from various tables and joins them together. The query filters for data from a specific year, month, and document type where the document amount is greater than the amount paid according to other tables.

Uploaded by

Jezuz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

SELECT tipasi.abr_item AS abr_tas, m_vouche.num_vouc, m_vouche.

des_vouc,
m_vouche.deb_tnac, m_vouche.hab_tnac, m_vouche.swt_vouc,
m_vouche.cdg_tas,m_vouche.cdg_tope FROM m_vouche, d_tablas tipasi WHERE
tipasi.cdg_tab = 'TAS' AND m_vouche.ano_vouc = '2022' AND m_vouche.mes_vouc =
'03' AND m_vouche.cdg_tas = tipasi.num_item AND m_vouche.swt_pre = 'P' ORDER
BY abr_tas, m_vouche.num_vouc tip_item AS signo,M_cteprv.num_docu,M_cteprv.ruc_prv,
M_provee.des_prv,T_cambio.tip_cmbc,M_cteprv.imp_docu,M_cteprv.pag_docu,
M_cteprv.cdg_mon,M_cteprv.cdg_tdoc,M_cteprv.vct_docu,m_cteprv.fec_docu,m_cteprv.fec
_reg, Moneda.des_item AS moneda,SUBSTR(M_cteprv.num_docu,1,3) AS
Serie,m_cteprv.swt_docu FROM m_cteprv INNER JOIN m_provee on M_provee.ruc_prv =
M_cteprv.ruc_prv INNER JOIN (SELECT * FROM d_tablas where cdg_tab='TDC') Tipdoc on
Tipdoc.num_item = M_cteprv.cdg_tdoc INNER JOIN (SELECT * FROM d_tablas where
cdg_tab='MON') Moneda on Moneda.num_item = M_cteprv.cdg_mon LEFT JOIN t_cambio on
T_cambio.fec_cmb = M_cteprv.fec_docu WHERE M_cteprv.swt_docu <> 'A' AND
M_cteprv.fec_reg >= ?dDesde AND M_cteprv.fec_reg <= ?dHasta AND M_cteprv.cdg_mon
= '001' ORDER BY M_provee.des_prv, RTRIM(LTRIM(Tipdoc.abr_item)),
M_cteprv.fec_reg ) A LEFT JOIN ( SELECT
A.CDG_TDOC,A.NUM_DOCU,A.RUC_PRV ,SUM(IMPORTE) IMPORTE FROM ( SELECT
A.CDG_TDOC,A.NUM_DOCU,A.RUC_PRV, SUM(COALESCE ( CASE WHEN A.CDG_MON<>B.CDG_MON
THEN CASE WHEN B.CDG_MON='001' AND A.CDG_MON='002' THEN
ROUND(A.imp_pago*A.tip_cmb, 2) ELSE ROUND(A.imp_pago/A.tip_cmb, 2) END
ELSE A.imp_pago END ,0)) IMPORTE FROM m_pagprv A left join m_ctePRV B on
B.CDG_TDOC=A.CDG_TDOC AND B.NUM_DOCU=A.NUM_DOCU AND B.RUC_PRV=A.RUC_PRV WHERE
A.fec_pago <= ?dHasta AND B.cdg_mon = '001' GROUP BY
A.CDG_TDOC,A.NUM_DOCU,A.RUC_prv UNION ALL SELECT
A.CDG_TDOC,A.NUM_DOCU,A.RUC_PRV, SUM(imp_docu) IMPORTE FROM M_LETRAP A WHERE
swt_est = 'D' and fec_caj <= ?dHasta and swt_caj <> 'A' GROUP BY
A.CDG_TDOC,A.NUM_DOCU,A.RUC_PRV ) A GROUP BY A.CDG_TDOC,A.NUM_DOCU,A.RUC_PRV )
B ON B.CDG_TDOC=A.CDG_TDOC AND B.NUM_DOCU=A.NUM_DOCU AND B.RUC_PRV=A.RUC_PRV WHERE
(COALESCE(B.IMPORTE,0)) <A.IMP_DOCU AND A.IMP_DOCU-(COALESCE(B.IMPORTE,0)) >
0.05

You might also like