Quantcast
Channel: Classic ASP
Viewing all articles
Browse latest Browse all 488

Looping with SQL and grouping/summing products ...

$
0
0

Hi,

I have an old application written in classic ASP.

At present it runs some SQL (Call it SQL1) and pulls out all the orders, I.E Order Number, Order Date etc ....

Inside this loop is another SQL (Call it SQL2) which loops through all the orderlines where the table IDs match.
At the moment the only info being collected from this SQL2 is a qty stored in the table which is summed up, and a total is provided for each Order Number in SQL1

Each Order might have the following info as its OrderLines

Product Aqty = 52

Product B
qty = 73

Product C
qty = 18

What I want to do is sum all this info together from all the open orders.
i.e. I want to print out
Product A - Total = 192 (total from all open orders)
Product B - Total = 280 (total from all open orders)
Product C - Total = 96 (total from all open orders)

I can use SQL2 in the loop because the Product Name and the Qty required are in this SQL2, but I'm just unsure where to structure my loops in order to group these fields grouped together whilst looping through all the orders ...

Appreciate your help :-)
David


Viewing all articles
Browse latest Browse all 488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>