Subject Re: SQL in IBO
Author ehandbury
Why don't you just have a calculated field with a global counter?

(C++ code)

int counter;
...
counter = 0;
...
OnCalculatedField(...) {
counter += ARow->ByName("????")->AsInteger;
AField->Value = counter;
}

Eric.

--- In IBObjects@y..., "eric_ck_leung" <eric.leung@h...> wrote:
> I have problem in using the following SQL in IBO
>
> I have a table with structure
> F1 F2 Q1
> 1 1 10
> 1 2 20
> 1 3 40
> 2 1 80
> 2 2 160
> (F1,F2) is the primary key of the table
>
> and would like to get the result table with accumulated quantity Q2
of
> Q1 as below:
> F1 F2 Q1 Q2
> 1 1 10 10
> 1 2 20 30
> 1 3 40 70
> 2 1 80 80
> 2 2 160 240
>
> So I use following SQL
> select F1, F2, Q1,
> (select sum(Q1) from MyTable where F1 = a.F1
> and F2 <= a.F2) as Q2
> from MyTable a
> order by F1, F2
>
> I was using with IB_SQL.exe (version 4.2Ha) in win98, Firebird 1.0
for
> testing.
>
> But I got the following errors message:
> ISC ERROR CODE:335544569
>
> ISC ERROR MESSAGE:
> Dynamic SQL Error
> SQL error code = -502
> Declared cursor already exists
>
> STATEMENT:
> TIB_Query: "<TApplication>.frmSQL.frmQuery.qrQuery."
>
> And SqL message:
>
> SQL ERROR CODE:-502
>
> SQL ERROR MESSAGE:
> The cursor identified in an OPEN statement is already open.
>
>
>
> The same SQL was acceptable when I using the other tools such as
> ibadmin. I was quite confused for what mistake I might take.
>
> Please advise if anyone encounter similiar problem and the ways
that
> I could try to solve the problem.
>
> Thanks for your kind attention.