QUERY ERRADA
Estou colocando esta query para buscar o total dos tipos de pagamentos de cada filial. Só que está dando erro.
[txt-color=#0000f0] sql=SELECT v.L1_FILIAL AS LOJA, L1_EMISNF AS DATA,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]CC[ô]) Cartao,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]CH[ô]) Cheque,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]R$[ô]) Diqueiro,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]CD[ô]) Debito,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]FO[ô]) Folha,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]SR[ô]) Saldo,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]FI[ô]) Crediario,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL) Total
FROM SL1010 v
WHERE()
L1_EMISNF=[ô]20120517[ô]
GROUP BY L1_FILIAL, L1_EMISNF[/txt-color]
[txt-color=#0000f0] sql=SELECT v.L1_FILIAL AS LOJA, L1_EMISNF AS DATA,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]CC[ô]) Cartao,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]CH[ô]) Cheque,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]R$[ô]) Diqueiro,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]CD[ô]) Debito,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]FO[ô]) Folha,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]SR[ô]) Saldo,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]FI[ô]) Crediario,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL) Total
FROM SL1010 v
WHERE()
L1_EMISNF=[ô]20120517[ô]
GROUP BY L1_FILIAL, L1_EMISNF[/txt-color]
Simples assim:
SELECT v.L1_FILIAL AS LOJA, L1_EMISNF AS DATA,
sum(iif(v.L1_FORMPG=[ô]CC[ô],v.L1_VLRLIQ,0)) Cartao,
sum(iif(v.L1_FORMPG=[ô]CH[ô],v.L1_VLRLIQ,0)) Cheque,
sum(iif(v.L1_FORMPG=[ô]R$[ô],v.L1_VLRLIQ,0)) Dinheiro,
sum(iif(v.L1_FORMPG=[ô]CD[ô],v.L1_VLRLIQ,0)) Debito,
sum(iif(v.L1_FORMPG=[ô]FO[ô],v.L1_VLRLIQ,0)) Folha,
sum(iif(v.L1_FORMPG=[ô]SR[ô],v.L1_VLRLIQ,0)) Saldo,
sum(iif(v.L1_FORMPG=[ô]FI[ô],v.L1_VLRLIQ,0)) Crediario
FROM
SL1010 v
WHERE
L1_EMISNF=[ô]20120517[ô]
GROUP BY L1_FILIAL, L1_EMISNF
SELECT v.L1_FILIAL AS LOJA, L1_EMISNF AS DATA,
sum(iif(v.L1_FORMPG=[ô]CC[ô],v.L1_VLRLIQ,0)) Cartao,
sum(iif(v.L1_FORMPG=[ô]CH[ô],v.L1_VLRLIQ,0)) Cheque,
sum(iif(v.L1_FORMPG=[ô]R$[ô],v.L1_VLRLIQ,0)) Dinheiro,
sum(iif(v.L1_FORMPG=[ô]CD[ô],v.L1_VLRLIQ,0)) Debito,
sum(iif(v.L1_FORMPG=[ô]FO[ô],v.L1_VLRLIQ,0)) Folha,
sum(iif(v.L1_FORMPG=[ô]SR[ô],v.L1_VLRLIQ,0)) Saldo,
sum(iif(v.L1_FORMPG=[ô]FI[ô],v.L1_VLRLIQ,0)) Crediario
FROM
SL1010 v
WHERE
L1_EMISNF=[ô]20120517[ô]
GROUP BY L1_FILIAL, L1_EMISNF
Se o banco de dados for SQLSERVER seria:
WHERE() L1_EMISNF=convert(datetime,[ô]2012-05-17,102[ô])
Precisa ver qual o seu banco de dados.
WHERE() L1_EMISNF=convert(datetime,[ô]2012-05-17,102[ô])
Precisa ver qual o seu banco de dados.
Obrigado meus caros Ricart e JCarlos pela atenção.
é o seguinte, eu consegui fazer com a ajuda de um amigo da seguinte forma:
Conforme está no meu pedido de ajuda, ele está em 9 linhas antes do FROM, e o que foi feito para funcionar, foi só colocar toda a Query numa linha somente.
Obrigado pela ajuda!
é o seguinte, eu consegui fazer com a ajuda de um amigo da seguinte forma:
Conforme está no meu pedido de ajuda, ele está em 9 linhas antes do FROM, e o que foi feito para funcionar, foi só colocar toda a Query numa linha somente.
Obrigado pela ajuda!
Tópico encerrado , respostas não são mais permitidas