Subject Re: [firebird-support] sum and the 'iif' operator
Author Helen Borrie
At 02:14 PM 30/11/2009, you wrote:
>Hi all,
>
>
>
>Trying to do some simple aged balances on a transaction table, and having
>issues.
>
>
>
>Can anyone see what I'm doing wrong?
>
>
>SQL Command:
>
>select int_contactid,
>
>sum(
>
> iif(('now' - dtm_stamp < 30), flt_amount,0)

>Dynamic SQL Error expression evaluation not supported


Try

iif ( ( ( ( cast('now' as timestamp) ) - dtm_stamp ) < 30), flt_amount,0 )

You might or might not need the cast but you do need to bracket the expression.

But you shouldn't need the 'now' value for an evaluation in days - why not just use CURRENT_TIMESTAMP?

iif ( ( (CURRENT_TIMESTAMP - dtm_stamp) < 30), flt_amount,0)


>Any ideas?
>
>How do other people do aged balances, apart from individual queries /
>subselects for each range...

Subqueries aren't needed, are they?

Thought about a view?

./helen