LS:DO loop

Hi,I connect to an external source for data. I have items ordered on different dates and with different quantities. I want to pull in all the data, then group all the items together and add only the “categorized” items’ quantities.

I will then use the summed quantities for another calculation I need to do.

For example:

Date: 20/08/2004

Item: A

Item Description: Part A

Quantity: 3

Date: 20/08/2004

Item: B

Item Description: Part B

Quantity: 2

Date: 21/08/2004

Item: A

Item Description: Part A

Quantity: 3

So the resultset should show for Part A, the quantity is → 6 and for Part B, the quantity is → 2.

Any help in the right direction will help tremendously.

Rgds

Subject: LS:DO loop

For data aggregation on unique keys its best to define a class to hold the data and then build a list of these objects. Its easy to test if you’ve already started summing a particular key.When finished aggregating use forall to scan what you’ve got.

e.g

class CItem

mname as string

mdesc as string

mcount as integer

sub new()

you may want to initialise fields here

end sub

end class

dim items list as CItem

dim curr as CItem

dim key as string

do

…get a data record

key=… 'assemble your key (text) here

if is element(items(key)) then 'we already have an object for this category, get it and update the quantity

set curr=items(key)

curr.mcount=curr.mcount + the current quantity

else 'get a new object and initialise it

set curr=new CItem()

curr.mcount=the current quantity

curr.mname=…

curr.desc=…

items(key)=curr

end if

loop

Subject: LS:DO loop

I would adjust your SQL statement to perform a group by function. This will do the summary of the products for you. For example:

SELECT Item, SUM(Quantity) FROM OrderDB

GROUP BY Item

HTH - MJW