Fórum Como resolver esse sql no FB #51368
22/06/2005
0
select ( select coalesce(sum(k.ULT_CUSTO_COR * K.QUANT),0) from kardexmovcaixa k where k.cod_emp=1 and k.datahoraa=´2005-05-20 16:20:20´ and k.creddeb=´C´ and (k.codhistmovcaixa in (´1010´,´2020´,´5051´) ) ) - ( select coalesce(sum(k.ULT_CUSTO_COR * K.QUANT),0) from kardexmovcaixa k where k.cod_emp=1 and k.datahoraa=´2005-05-20 16:20:20´ and k.creddeb=´D´ and (k.codhistmovcaixa in (´1011´,´2021´,´5050´) ) ) as custo, ( select coalesce(sum(k.preco_venda * k.quant ),0) from kardexmovcaixa k where k.cod_emp=1 and k.datahoraa=´2005-05-20 16:20:20´ and k.creddeb=´C´ and (k.codhistmovcaixa in (´1010´,´2020´) ) ) as Venda, ( select coalesce(sum(k.preco_venda * k.quant ),0) from kardexmovcaixa k where k.cod_emp=1 and k.datahoraa=´2005-05-20 16:20:20´ and k.creddeb=´D´ and (k.codhistmovcaixa in (´5050´,´6060´) ) ) as Devolucao, h.cod_hist,h.descricao,h.tipohist as DebCre,m.cod_caixa,sum(m.valor) from tabhist h,tabmovcaixa m where m.cod_emp=1 and m.datahoraa=´2005-05-20 16:20:20´ and m.codhist=h.cod_hist group by h.cod_hist,h.descricao,h.tipohist,m.cod_caixa
Meu problema eh o seguinte... o campo
DataHoraa
eh o filtro principal do meu sql.... ele esta no where externo e nos internos...no Interbase eu fazia a comparacao do externo c o interno...
m.datahoraa=k.datahoraa
Mas no FB ele non aceita eu colocar esse parametro externo nos select interno...
*-*-*-*-*-*-*-*-*-*-*-*-*
Galera eu tava escrevendo esse post p tirar duvida e acabei resolvendo antes de mandar o post.. enton resolvi postar a solucao.. caso alguem tenha
select ( select coalesce(sum(k.ULT_CUSTO_COR * K.QUANT),0) from kardexmovcaixa k where k.cod_emp=1 and k.datahoraa=m.datahoraa and k.creddeb=´C´ and (k.codhistmovcaixa in (´1010´,´2020´,´5051´) ) ) - ( select coalesce(sum(k.ULT_CUSTO_COR * K.QUANT),0) from kardexmovcaixa k where k.cod_emp=1 and k.datahoraa=m.datahoraa and k.creddeb=´D´ and (k.codhistmovcaixa in (´1011´,´2021´,´5050´) ) ) as custo, ( select coalesce(sum(k.preco_venda * k.quant ),0) from kardexmovcaixa k where k.cod_emp=1 and k.datahoraa=m.datahoraa and k.creddeb=´C´ and (k.codhistmovcaixa in (´1010´,´2020´) ) ) as Venda, ( select coalesce(sum(k.preco_venda * k.quant ),0) from kardexmovcaixa k where k.cod_emp=1 and k.datahoraa=m.datahoraa and k.creddeb=´D´ and (k.codhistmovcaixa in (´5050´,´6060´) ) ) as Devolucao, h.cod_hist,h.descricao,h.tipohist as DebCre,m.cod_caixa,sum(m.valor) from tabhist h,tabmovcaixa m where m.cod_emp=1 and m.datahoraa=´2005-05-20 16:20:20´ and m.codhist=h.cod_hist group by h.cod_hist,h.descricao,h.tipohist,m.cod_caixa,m.datahoraa
a solucao eh bem simples.. foi so coloar o datahoraa no group by
Isso era a unica coisa q eu achava q o IB era melhor q o FB... agora q descobri como se resolve... FB eh bem melhorrrrr
Flw galera
Osocram
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)