Subject | Re: [firebird-support] View issue |
---|---|
Author | Luciano R. Machado |
Post date | 2004-12-01T11:39:23Z |
Hi Alexandre,
Based your explanation I modified to this:
Select Ped.Empresa, Ped.CodPedido,
coalesce((Select Sum(Case When Mov.CodProduto <> 8888888
Then (ValorCustoFor * FatorRedCusto) * QuantAtendida
Else 0 End)
From MovEstoque Mov
Where Mov.Empresa = Ped.Empresa
and Mov.CodPedido = Ped.CodPedido) ,0) as ValorCustoFor,
coalesce((Select Sum(Case When Mov.CodProduto <> 8888888
Then (ValorCustoUlt * FatorRedCusto) * QuantAtendida
Else 0 End)
From MovEstoque Mov
Where Mov.Empresa = Ped.Empresa
and Mov.CodPedido = Ped.CodPedido) ,0) as ValorCustoUlt,
coalesce((Select Sum(Case When Mov.CodProduto <> 8888888
Then ValorCustoMed * QuantAtendida
Else 0 End)
From MovEstoque Mov
Where Mov.Empresa = Ped.Empresa
and Mov.CodPedido = Ped.CodPedido) ,0) as ValorCustoMed,
coalesce((Select Sum(Case When Mov.CodProduto = 8888888
Then ValorCustoFor * QuantAtendida
Else 0 End)
From MovEstoque Mov
Where Mov.Empresa = Ped.Empresa
and Mov.CodPedido = Ped.CodPedido) ,0) as ValorCustoSer
From Pedidos Ped
;
Now it´s working very fine!
Thank you!
--
Luciano Rodrigues Machado
Programador - Ribeirão Preto-SP
Alexandre Benson Smith wrote:
Based your explanation I modified to this:
Select Ped.Empresa, Ped.CodPedido,
coalesce((Select Sum(Case When Mov.CodProduto <> 8888888
Then (ValorCustoFor * FatorRedCusto) * QuantAtendida
Else 0 End)
From MovEstoque Mov
Where Mov.Empresa = Ped.Empresa
and Mov.CodPedido = Ped.CodPedido) ,0) as ValorCustoFor,
coalesce((Select Sum(Case When Mov.CodProduto <> 8888888
Then (ValorCustoUlt * FatorRedCusto) * QuantAtendida
Else 0 End)
From MovEstoque Mov
Where Mov.Empresa = Ped.Empresa
and Mov.CodPedido = Ped.CodPedido) ,0) as ValorCustoUlt,
coalesce((Select Sum(Case When Mov.CodProduto <> 8888888
Then ValorCustoMed * QuantAtendida
Else 0 End)
From MovEstoque Mov
Where Mov.Empresa = Ped.Empresa
and Mov.CodPedido = Ped.CodPedido) ,0) as ValorCustoMed,
coalesce((Select Sum(Case When Mov.CodProduto = 8888888
Then ValorCustoFor * QuantAtendida
Else 0 End)
From MovEstoque Mov
Where Mov.Empresa = Ped.Empresa
and Mov.CodPedido = Ped.CodPedido) ,0) as ValorCustoSer
From Pedidos Ped
;
Now it´s working very fine!
Thank you!
--
Luciano Rodrigues Machado
Programador - Ribeirão Preto-SP
Alexandre Benson Smith wrote:
> Luciano,
>
> Views with agregates could not use indexes, since you could be searching
> by the summary fields ( I think this will be enhaced in future versions)
> but now, you will have to deal with it.
>
> What you could do:
> Maintain the totals on Table Pedidos with triggers
> Use the select to the tables direct instead of use view, in this case
> you will get a better performance, since the indices will be used.
>
> see you !
>
> --
>
> Alexandre Benson Smith
> Development
> THOR Software e Comercial Ltda.
> Santo Andre - Sao Paulo - Brazil
> www.thorsoftware.com.br
>