[V4RB] Use of SUM command

Stan Busk maxprog at mac.com
Mon Jun 2 17:05:36 CDT 2003


Hi,

Thanks. That was what I was thinking about but it doesn't work. The 
cursor always return one only record. I have tried many times with 
different variation but no way. What can prevent the cursor to return 
second record? I am using V4RB 1.9.8b7 with a database that works fine 
with all kind of queries.

Stan

> on 6/2/03 16:41, Stan Busk at maxprog at mac.com wrote:
>
>> Hi,
>>
>> I am trying to optimize some of my database calculations. For example 
>> I
>> use the SUM command twice because depending on 'Type' I have to change
>> the sign. These are the SQL commands:
>>
>> aCursor = vdb.SQLselect("Select Sum(Amount) from Accs where Type='2'")
>> bCursor = vdb.SQLselect("Select Sum(Amount) from Accs where Type='3'")
>>
>> And the result:
>>
>> Result = - aCursor.DoubleField(1).value - bCursor.DoubleField(1).value
>>
>> Is there a way to make this calculation in one SQL command? I have
>> found stuff inside the Doc but no examples. I guess this is the GROUP
>> command but I have absolutely no clue of how it works, documentation
>> has no mention about it.
>
> Hi Stan,
>
>     SELECT Sum(Amount)
>     FROM Accs
>     WHERE Type='2' OR Type='3'
>     GROUP BY Type
>
> You should get cursor with 2 records now.
> Read values from each record and do calculation self.
>
> -- 
> Best regards,
> Ruslan Zasukhin      [ I feel the need...the need for speed ]
> -------------------------------------------------------------
>



More information about the Valentina mailing list