Subject RE: [IBO] How to use Query.Filter with Alias column
Author Svein Erling Tysvær
>>> I have a SQL with one Alias column.
>>>
>>> When run the Filter (with this alias column) has one exception --
>>> "Column unknown"
>>>
>>> How to use a Query.Filter in this case?
>
>>You said, catch the subquery and use on filter?
>>
>>My original SQL (example):
>>
>>*select vend.nome,*
>>* ( select coalesce(sum(deve), 0)*
>>* from pedidosven ped*
>>* where ped.vendedor = vend.codigo*
>>* and ped.acfinanceiro = 'S'*
>>* ) DIVIDA*
>>* from vendedores vend*
>>*where vend.status = 'Ativa'*
>>* and vend.representante = 347*
>>
>>The Query.Filter would look like this?
>>
>>*Query.Filter := '(select coalesce(sum(deve), 0) from pedidosven ped where ped.vendedor = vend.codigo
>>and ped.acfinanceiro = 'S');*
>
>You will also likely need to preface it with the flag to tell IBO to not parse the filter clause but to
>stick it directly into the WHERE clause as-is.
>
>Query.Filter := '::SQL::(select coalesce(sum(deve), 0) from pedidosven ped where ped.vendedor = vend.codigo
>and ped.acfinanceiro = 'S');

If he changed the query to using a CTE:

with tmp(nome, divida) as
(select vend.nome,
( select coalesce(sum(deve), 0)
from pedidosven ped
where ped.vendedor = vend.codigo
and ped.acfinanceiro = 'S'
) DIVIDA
from vendedores vend
where vend.status = 'Ativa'
and vend.representante = 347)
select nome, divida
from tmp

would that make his original filter work?

Set