Fórum Ajuda em select para Botão de pesquisa #465555
02/01/2014
0
SELECT
T1.CODIGO_MOVIMENTACAO,
T1.VALOR_NOTA,
T1.DATA_EMISSAO,
T1.VALOR_VENCIMENTO1,
T1.DATA_VENCIMENTO1,
T1.VALOR_PAGAMENTO1,
T1.DATA_PAGAMENTO1,
T1.VALOR_JUROS1,
T1.VALOR_DESCONTO1,
T2.NOME_FORNECEDOR,
((coalesce(T1.VALOR_VENCIMENTO1,'0') + coalesce(T1.VALOR_VENCIMENTO2,'0') +
coalesce(T1.VALOR_VENCIMENTO3,'0') + coalesce(T1.VALOR_VENCIMENTO4,'0') +
coalesce(T1.VALOR_VENCIMENTO5,'0') + coalesce(T1.VALOR_VENCIMENTO6,'0') +
coalesce(T1.VALOR_VENCIMENTO7,'0') + coalesce(T1.VALOR_VENCIMENTO8,'0') +
coalesce(T1.VALOR_VENCIMENTO9,'0') + coalesce(T1.VALOR_VENCIMENTO10,'0') +
coalesce(T1.VALOR_VENCIMENTO11,'0')+ coalesce(T1.VALOR_VENCIMENTO12,'0')) +
(coalesce(T1.VALOR_JUROS1,'0') + coalesce(T1.VALOR_JUROS2,'0') +
coalesce(T1.VALOR_JUROS3,'0') + coalesce(T1.VALOR_JUROS4,'0') +
coalesce(T1.VALOR_JUROS5,'0') + coalesce(T1.VALOR_JUROS6,'0') +
coalesce(T1.VALOR_JUROS7,'0') + coalesce(T1.VALOR_JUROS8,'0') +
coalesce(T1.VALOR_JUROS9,'0') + coalesce(T1.VALOR_JUROS10,'0') +
coalesce(T1.VALOR_JUROS11,'0')+ coalesce(T1.VALOR_JUROS12,'0'))-
(coalesce(T1.VALOR_PAGAMENTO1,'0') + coalesce(T1.VALOR_PAGAMENTO2,'0') +
coalesce(T1.VALOR_PAGAMENTO3,'0') + coalesce(T1.VALOR_PAGAMENTO4,'0') +
coalesce(T1.VALOR_PAGAMENTO5,'0') + coalesce(T1.VALOR_PAGAMENTO6,'0') +
coalesce(T1.VALOR_PAGAMENTO7,'0') + coalesce(T1.VALOR_PAGAMENTO8,'0') +
coalesce(T1.VALOR_PAGAMENTO9,'0') + coalesce(T1.VALOR_PAGAMENTO10,'0') +
coalesce(T1.VALOR_PAGAMENTO11,'0')+ coalesce(T1.VALOR_PAGAMENTO12,'0'))-
(coalesce(T1.VALOR_DESCONTO1,'0') + coalesce(T1.VALOR_DESCONTO2,'0') +
coalesce(T1.VALOR_DESCONTO2,'0') + coalesce(T1.VALOR_DESCONTO4,'0') +
coalesce(T1.VALOR_DESCONTO5,'0') + coalesce(T1.VALOR_DESCONTO6,'0') +
coalesce(T1.VALOR_DESCONTO7,'0') + coalesce(T1.VALOR_DESCONTO8,'0') +
coalesce(T1.VALOR_DESCONTO9,'0') + coalesce(T1.VALOR_DESCONTO10,'0') +
coalesce(T1.VALOR_DESCONTO11,'0')+ coalesce(T1.VALOR_DESCONTO12,'0'))) AS SALDO
FROM
CONTAS_PAGAR T1,
FORNECEDORES T2
WHERE
T1.FORNECEDOR = T2.NOME_FORNECEDOR
AND
SALDO > 0
AND
SALDO < T1.VALOR_NOTA
só que nestes 2 ANDs ele esta dando erro.
Dynamic SQL Error.
SQL error code = -206.
Column unknown.
SALDO.
At line 42, column 5.
e eu não sei resolver alguem pode me ajudar
Eduardo Mendonça
Curtir tópico
+ 0Posts
02/01/2014
Leandro Chiodini
Você poderia explicar o que você deseja fazer neste select?
Pois como esta sendo feito ali com o Saldo, realmente nao vai funcionar
o erro que ele esta mostrando é que o campo Saldo nao existe na tabela,
Porque o alias ali é so para mostrar de forma legivel este calculo.
Para que isso funcione voce precisa de um subselect para pegar o valor e ai sim comparar com o valor que voce quer.
caso queria, explique o que voce precisa,
que tentaremos te ajudar.
att,
Leandro.
Gostei + 0
02/01/2014
Leandro Chiodini
SELECT
T1.CODIGO_MOVIMENTACAO,
T1.VALOR_NOTA,
T1.DATA_EMISSAO,
T1.VALOR_VENCIMENTO1,
T1.DATA_VENCIMENTO1,
T1.VALOR_PAGAMENTO1,
T1.DATA_PAGAMENTO1,
T1.VALOR_JUROS1,
T1.VALOR_DESCONTO1,
T2.NOME_FORNECEDOR,
SUM(T1.VALOR_VENCIMENTO1 + T1.VALOR_VENCIMENTO2
+ T1.VALOR_VENCIMENTO3 + T1.VALOR_VENCIMENTO4
+ T1.VALOR_VENCIMENTO5 + T1.VALOR_VENCIMENTO6
+ T1.VALOR_VENCIMENTO7 + T1.VALOR_VENCIMENTO8
+ T1.VALOR_VENCIMENTO9 + T1.VALOR_VENCIMENTO10
+ T1.VALOR_VENCIMENTO11 + T1.VALOR_VENCIMENTO12
+ T1.VALOR_JUROS1 + T1.VALOR_JUROS2
+ T1.VALOR_JUROS3 + T1.VALOR_JUROS4
+ T1.VALOR_JUROS5 + T1.VALOR_JUROS6
+ T1.VALOR_JUROS7 + T1.VALOR_JUROS8
+ T1.VALOR_JUROS9 + T1.VALOR_JUROS10
+ T1.VALOR_JUROS11 + T1.VALOR_JUROS12
+ T1.VALOR_PAGAMENTO1 + T1.VALOR_PAGAMENTO2
+ T1.VALOR_PAGAMENTO3 + T1.VALOR_PAGAMENTO4
+ T1.VALOR_PAGAMENTO5 + T1.VALOR_PAGAMENTO6
+ T1.VALOR_PAGAMENTO7 + T1.VALOR_PAGAMENTO8
+ T1.VALOR_PAGAMENTO9 + T1.VALOR_PAGAMENTO10
+ T1.VALOR_PAGAMENTO11 + T1.VALOR_PAGAMENTO12
+ T1.VALOR_DESCONTO1 + T1.VALOR_DESCONTO2
+ T1.VALOR_DESCONTO2 + T1.VALOR_DESCONTO4
+ T1.VALOR_DESCONTO5 + T1.VALOR_DESCONTO6
+ T1.VALOR_DESCONTO7 + T1.VALOR_DESCONTO8
+ T1.VALOR_DESCONTO9 + T1.VALOR_DESCONTO10
+ T1.VALOR_DESCONTO11 + T1.VALOR_DESCONTO12)
FROM
CONTAS_PAGAR T1,
FORNECEDORES T2
WHERE
T1.FORNECEDOR = T2.NOME_FORNECEDOR
AND
HEAVING SUM(T1.VALOR_VENCIMENTO1 + T1.VALOR_VENCIMENTO2
+ T1.VALOR_VENCIMENTO3 + T1.VALOR_VENCIMENTO4
+ T1.VALOR_VENCIMENTO5 + T1.VALOR_VENCIMENTO6
+ T1.VALOR_VENCIMENTO7 + T1.VALOR_VENCIMENTO8
+ T1.VALOR_VENCIMENTO9 + T1.VALOR_VENCIMENTO10
+ T1.VALOR_VENCIMENTO11 + T1.VALOR_VENCIMENTO12
+ T1.VALOR_JUROS1 + T1.VALOR_JUROS2
+ T1.VALOR_JUROS3 + T1.VALOR_JUROS4
+ T1.VALOR_JUROS5 + T1.VALOR_JUROS6
+ T1.VALOR_JUROS7 + T1.VALOR_JUROS8
+ T1.VALOR_JUROS9 + T1.VALOR_JUROS10
+ T1.VALOR_JUROS11 + T1.VALOR_JUROS12
+ T1.VALOR_PAGAMENTO1 + T1.VALOR_PAGAMENTO2
+ T1.VALOR_PAGAMENTO3 + T1.VALOR_PAGAMENTO4
+ T1.VALOR_PAGAMENTO5 + T1.VALOR_PAGAMENTO6
+ T1.VALOR_PAGAMENTO7 + T1.VALOR_PAGAMENTO8
+ T1.VALOR_PAGAMENTO9 + T1.VALOR_PAGAMENTO10
+ T1.VALOR_PAGAMENTO11 + T1.VALOR_PAGAMENTO12
+ T1.VALOR_DESCONTO1 + T1.VALOR_DESCONTO2
+ T1.VALOR_DESCONTO2 + T1.VALOR_DESCONTO4
+ T1.VALOR_DESCONTO5 + T1.VALOR_DESCONTO6
+ T1.VALOR_DESCONTO7 + T1.VALOR_DESCONTO8
+ T1.VALOR_DESCONTO9 + T1.VALOR_DESCONTO10
+ T1.VALOR_DESCONTO11 + T1.VALOR_DESCONTO12) between 0 and T1.VALOR_NOTA Gostei + 0
02/01/2014
Eduardo Mendonça
Gostei + 0
02/01/2014
Leandro Chiodini
att,
Gostei + 0
15/01/2014
Eduardo Mendonça
dessa maneira não funfou.
olha o calculo é o seguinte ((Valores de vencimento + Jurus) - Desconto - Valor Pago) em cada linha tem 12 Valores de vencimento 12 Juros 12 descontos e 12 valor pago
de cada linha tenho que fazer essa calculo para saber se já esta pago ou parcialmente pago.
Fiz assim e ela me traz (5) resultados do me DB só que era para ele trazer (4)
SELECT
T1.CODIGO_MOVIMENTACAO,
T1.VALOR_NOTA,
T1.VALOR_VENCIMENTO1,
T1.DATA_VENCIMENTO1,
T1.VALOR_PAGAMENTO1,
T1.DATA_PAGAMENTO1,
T1.VALOR_JUROS1,
T1.VALOR_DESCONTO1,
T2.NOME_FORNECEDOR
FROM
CONTAS_PAGAR T1,
FORNECEDORES T2
WHERE -- [(V+J)-D]-P
T1.FORNECEDOR = T2.NOME_FORNECEDOR
AND ((coalesce(T1.VALOR_VENCIMENTO1,"0") + coalesce(T1.VALOR_VENCIMENTO2,"0") +
coalesce(T1.VALOR_VENCIMENTO3,"0") + coalesce(T1.VALOR_VENCIMENTO4,"0") +
coalesce(T1.VALOR_VENCIMENTO5,"0") + coalesce(T1.VALOR_VENCIMENTO6,"0") +
coalesce(T1.VALOR_VENCIMENTO7,"0") + coalesce(T1.VALOR_VENCIMENTO8,"0") +
coalesce(T1.VALOR_VENCIMENTO9,"0") + coalesce(T1.VALOR_VENCIMENTO10,"0") +
coalesce(T1.VALOR_VENCIMENTO11,"0")+ coalesce(T1.VALOR_VENCIMENTO12,"0")+
coalesce(T1.VALOR_JUROS1,"0") + coalesce(T1.VALOR_JUROS2,"0") +
coalesce(T1.VALOR_JUROS3,"0") + coalesce(T1.VALOR_JUROS4,"0") +
coalesce(T1.VALOR_JUROS5,"0") + coalesce(T1.VALOR_JUROS6,"0") +
coalesce(T1.VALOR_JUROS7,"0") + coalesce(T1.VALOR_JUROS8,"0") +
coalesce(T1.VALOR_JUROS9,"0") + coalesce(T1.VALOR_JUROS10,"0") +
coalesce(T1.VALOR_JUROS11,"0")+ coalesce(T1.VALOR_JUROS12,"0"))-
(coalesce(T1.VALOR_DESCONTO1,"0") + coalesce(T1.VALOR_DESCONTO2,"0") +
coalesce(T1.VALOR_DESCONTO2,"0") + coalesce(T1.VALOR_DESCONTO4,"0") +
coalesce(T1.VALOR_DESCONTO5,"0") + coalesce(T1.VALOR_DESCONTO6,"0") +
coalesce(T1.VALOR_DESCONTO7,"0") + coalesce(T1.VALOR_DESCONTO8,"0") +
coalesce(T1.VALOR_DESCONTO9,"0") + coalesce(T1.VALOR_DESCONTO10,"0") +
coalesce(T1.VALOR_DESCONTO11,"0")+ coalesce(T1.VALOR_DESCONTO12,"0"))-
(coalesce(T1.VALOR_PAGAMENTO1,"0") + coalesce(T1.VALOR_PAGAMENTO2,"0") +
coalesce(T1.VALOR_PAGAMENTO3,"0") + coalesce(T1.VALOR_PAGAMENTO4,"0") +
coalesce(T1.VALOR_PAGAMENTO5,"0") + coalesce(T1.VALOR_PAGAMENTO6,"0") +
coalesce(T1.VALOR_PAGAMENTO7,"0") + coalesce(T1.VALOR_PAGAMENTO8,"0") +
coalesce(T1.VALOR_PAGAMENTO9,"0") + coalesce(T1.VALOR_PAGAMENTO10,"0")+
coalesce(T1.VALOR_PAGAMENTO11,"0")+ coalesce(T1.VALOR_PAGAMENTO12,"0"))) > 0
AND ((coalesce(T1.VALOR_VENCIMENTO1,"0") + coalesce(T1.VALOR_VENCIMENTO2,"0") +
coalesce(T1.VALOR_VENCIMENTO3,"0") + coalesce(T1.VALOR_VENCIMENTO4,"0") +
coalesce(T1.VALOR_VENCIMENTO5,"0") + coalesce(T1.VALOR_VENCIMENTO6,"0") +
coalesce(T1.VALOR_VENCIMENTO7,"0") + coalesce(T1.VALOR_VENCIMENTO8,"0") +
coalesce(T1.VALOR_VENCIMENTO9,"0") + coalesce(T1.VALOR_VENCIMENTO10,"0") +
coalesce(T1.VALOR_VENCIMENTO11,"0")+ coalesce(T1.VALOR_VENCIMENTO12,"0")+
coalesce(T1.VALOR_JUROS1,"0") + coalesce(T1.VALOR_JUROS2,"0") +
coalesce(T1.VALOR_JUROS3,"0") + coalesce(T1.VALOR_JUROS4,"0") +
coalesce(T1.VALOR_JUROS5,"0") + coalesce(T1.VALOR_JUROS6,"0") +
coalesce(T1.VALOR_JUROS7,"0") + coalesce(T1.VALOR_JUROS8,"0") +
coalesce(T1.VALOR_JUROS9,"0") + coalesce(T1.VALOR_JUROS10,"0") +
coalesce(T1.VALOR_JUROS11,"0")+ coalesce(T1.VALOR_JUROS12,"0"))-
(coalesce(T1.VALOR_DESCONTO1,"0") + coalesce(T1.VALOR_DESCONTO2,"0") +
coalesce(T1.VALOR_DESCONTO2,"0") + coalesce(T1.VALOR_DESCONTO4,"0") +
coalesce(T1.VALOR_DESCONTO5,"0") + coalesce(T1.VALOR_DESCONTO6,"0") +
coalesce(T1.VALOR_DESCONTO7,"0") + coalesce(T1.VALOR_DESCONTO8,"0") +
coalesce(T1.VALOR_DESCONTO9,"0") + coalesce(T1.VALOR_DESCONTO10,"0") +
coalesce(T1.VALOR_DESCONTO11,"0")+ coalesce(T1.VALOR_DESCONTO12,"0"))-
(coalesce(T1.VALOR_PAGAMENTO1,"0") + coalesce(T1.VALOR_PAGAMENTO2,"0") +
coalesce(T1.VALOR_PAGAMENTO3,"0") + coalesce(T1.VALOR_PAGAMENTO4,"0") +
coalesce(T1.VALOR_PAGAMENTO5,"0") + coalesce(T1.VALOR_PAGAMENTO6,"0") +
coalesce(T1.VALOR_PAGAMENTO7,"0") + coalesce(T1.VALOR_PAGAMENTO8,"0") +
coalesce(T1.VALOR_PAGAMENTO9,"0") + coalesce(T1.VALOR_PAGAMENTO10,"0")+
coalesce(T1.VALOR_PAGAMENTO11,"0")+ coalesce(T1.VALOR_PAGAMENTO12,"0"))) < T1.VALOR_NOTA
ORDER BY
T1.CODIGO_MOVIMENTACAO
Sei que um dele esta Totalmente pago e ele aparece na pesquisa já fiz a equação a mão com os valores e da certo, no sistema é usada a mesma equação e da certo só que no sql ele traz um mais não sei o que fazer e nem como fazer isso rodar corretamente preciso de ajuda.
se precisar da tabela para fazer eu posso disponibilizar é só me enviar um e-mail
Gostei + 0
10/02/2014
Eduardo Mendonça
Tipo somar T1.VALOR_VENCIMENTO1 ... T1.VALOR_VENCIMENTO12 e por em uma variavel
Tipo somar T1.VALOR_VALOR_JUROS1 ... T1.VALOR_VALOR_JUROS12 e por em outra variavel
Tipo somar T1.VALOR_VALOR_DESCONTO1 ... T1.VALOR_VALOR_DESCONTO12 e por em outra variavel
Tipo Sumner T1.VALOR_VALOR_PAGAMENTO1... T1.VALOR_VALOR_PAGAMENTO12 e por em outra variavel
depois fazer os cauculos só das variaveis
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)