Select demorando
Enviado: 04 Mai 2026 17:17
Olá à todos,
alguém tem uma solução melhor? tá demorando.
pagarb é a tabela
ela já esta com o ìndice docum+codfor+tpnota+serie+ordem
Poka
alguém tem uma solução melhor? tá demorando.
pagarb é a tabela
ela já esta com o ìndice docum+codfor+tpnota+serie+ordem
Código: Selecionar todos
str:="select b.valor , b.dc , b.nrecibo , d.valor ,";
+"(select sum(b.valor) from "+pagarb +" b where b.docum||b.codfor||b.tpnota||b.serie||b.ordem = '"+xchave+"' and b.dc = 'C' and trim(b.nrecibo)='' ) ,";
+"(select sum(b.valor) from "+pagarb +" b where b.docum||b.codfor||b.tpnota||b.serie||b.ordem = '"+xchave+"' and b.dc = 'D' and trim(b.nrecibo)='' ) ,";
+"(select sum(b.valor) from "+pagarb +" b where b.docum||b.codfor||b.tpnota||b.serie||b.ordem = '"+xchave+"' and b.dc = 'C' and trim(b.nrecibo)<>'' ) ,";
+"(select sum(b.valor) from "+pagarb +" b where b.docum||b.codfor||b.tpnota||b.serie||b.ordem = '"+xchave+"' and b.dc = 'D' and trim(b.nrecibo)<>'' ) ";
+" from "+pagarb+" b INNER JOIN "+pagard +" d on d.docum||d.codfor||d.tpnota||d.serie||d.ordem = '"+xchave+"'" ;
+" group by b.valor,b.dc, b.nrecibo , d.valor;"