473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Grouping & Sum of result page

Hi,

I have an asp page which prints data as follows:
The sum in brackets is a calculated result on the page, SQ *
RS2("SelectorQty"), a variable SQ which holds a qty multiplied by a
record value

96 (50)
104 (50)
96 (100)
104 (100)
96 (100)
104 (100)
96 (100)

What I want to be able to do is print the page like this:

96 = 350 (where 350 is the sum of all items displayed as 96)
104 = 350 (where 350 is the sum of all items displayed as 104)

I would be very grateful for any help on this.
I cannot work out how to group or sum in the query as I have the first
SQL statement pulling data, then a second within the loop pulling the
number 96 & 104, then a calculation with done between data from both
SQL statements.

Thanks

Sep 25 '06 #1
5 1626
I'd think that you could do this at the database level, but it's hard to say
without seeing the database. So, for a code solution, this may be one of
the rare instances that a dictionary object comes into use.

Dim oDict
Set oDict = CreateObject("Scripting.Dictionary")
Do While Not yourRecordset.EOF
sKey = yourRecordset.Fields.Item(0).Value
sValue = yourRecordset.Fields.Item(1).Value

If oDict.Exists(sKey) Then
oDict(sKey) = CLng(oDict(sKey)) + CLng(sValue)
Else
oDict(sKey) = sValue
End If
yourRecordset.MoveNext
Loop

For Each oKey in oDict.Keys
Response.Write oKey & " = " & oDict(oKey) & "<br />"
Next
Set oDict = Nothing

Ray at work


"David" <da*********@scene-double.co.ukwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi,

I have an asp page which prints data as follows:
The sum in brackets is a calculated result on the page, SQ *
RS2("SelectorQty"), a variable SQ which holds a qty multiplied by a
record value

96 (50)
104 (50)
96 (100)
104 (100)
96 (100)
104 (100)
96 (100)

What I want to be able to do is print the page like this:

96 = 350 (where 350 is the sum of all items displayed as 96)
104 = 350 (where 350 is the sum of all items displayed as 104)

I would be very grateful for any help on this.
I cannot work out how to group or sum in the query as I have the first
SQL statement pulling data, then a second within the loop pulling the
number 96 & 104, then a calculation with done between data from both
SQL statements.

Thanks

Sep 25 '06 #2
Ray,

Thanks for the reply,

The page worked with your code, but i'm not exactly sure how or what it
produced:
It displayed the first field in my SQL (customername) and then = a
number, for each customer.

I need it to list , SelectorName (A) = sum of qty for SelectorName A
etc

Please can you explain further ?

Thanks

-------------------------------------------------------------------------------------------------------

Ray Costanzo [MVP] wrote:
I'd think that you could do this at the database level, but it's hard to say
without seeing the database. So, for a code solution, this may be one of
the rare instances that a dictionary object comes into use.

Dim oDict
Set oDict = CreateObject("Scripting.Dictionary")
Do While Not yourRecordset.EOF
sKey = yourRecordset.Fields.Item(0).Value
sValue = yourRecordset.Fields.Item(1).Value

If oDict.Exists(sKey) Then
oDict(sKey) = CLng(oDict(sKey)) + CLng(sValue)
Else
oDict(sKey) = sValue
End If
yourRecordset.MoveNext
Loop

For Each oKey in oDict.Keys
Response.Write oKey & " = " & oDict(oKey) & "<br />"
Next
Set oDict = Nothing

Ray at work


"David" <da*********@scene-double.co.ukwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi,

I have an asp page which prints data as follows:
The sum in brackets is a calculated result on the page, SQ *
RS2("SelectorQty"), a variable SQ which holds a qty multiplied by a
record value

96 (50)
104 (50)
96 (100)
104 (100)
96 (100)
104 (100)
96 (100)

What I want to be able to do is print the page like this:

96 = 350 (where 350 is the sum of all items displayed as 96)
104 = 350 (where 350 is the sum of all items displayed as 104)

I would be very grateful for any help on this.
I cannot work out how to group or sum in the query as I have the first
SQL statement pulling data, then a second within the loop pulling the
number 96 & 104, then a calculation with done between data from both
SQL statements.

Thanks
Sep 25 '06 #3
Can you explain the database design and show the code that you're using now
to get the data?

Ray at work

"David" <da*********@scene-double.co.ukwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
Ray,

Thanks for the reply,

The page worked with your code, but i'm not exactly sure how or what it
produced:
It displayed the first field in my SQL (customername) and then = a
number, for each customer.

I need it to list , SelectorName (A) = sum of qty for SelectorName A
etc

Please can you explain further ?

Thanks

-------------------------------------------------------------------------------------------------------

Ray Costanzo [MVP] wrote:
>I'd think that you could do this at the database level, but it's hard to
say
without seeing the database. So, for a code solution, this may be one of
the rare instances that a dictionary object comes into use.

Dim oDict
Set oDict = CreateObject("Scripting.Dictionary")
Do While Not yourRecordset.EOF
sKey = yourRecordset.Fields.Item(0).Value
sValue = yourRecordset.Fields.Item(1).Value

If oDict.Exists(sKey) Then
oDict(sKey) = CLng(oDict(sKey)) + CLng(sValue)
Else
oDict(sKey) = sValue
End If
yourRecordset.MoveNext
Loop

For Each oKey in oDict.Keys
Response.Write oKey & " = " & oDict(oKey) & "<br />"
Next
Set oDict = Nothing

Ray at work


"David" <da*********@scene-double.co.ukwrote in message
news:11**********************@m73g2000cwd.googleg roups.com...
Hi,

I have an asp page which prints data as follows:
The sum in brackets is a calculated result on the page, SQ *
RS2("SelectorQty"), a variable SQ which holds a qty multiplied by a
record value

96 (50)
104 (50)
96 (100)
104 (100)
96 (100)
104 (100)
96 (100)

What I want to be able to do is print the page like this:

96 = 350 (where 350 is the sum of all items displayed as 96)
104 = 350 (where 350 is the sum of all items displayed as 104)

I would be very grateful for any help on this.
I cannot work out how to group or sum in the query as I have the first
SQL statement pulling data, then a second within the loop pulling the
number 96 & 104, then a calculation with done between data from both
SQL statements.

Thanks

Sep 25 '06 #4
Thanks Ray,

Each customer has many orders
Each order has many orderlines
Each orderline has 1 product
Each product has 1 or more MetalCodes (SelectorNames)
Each SelectorName for that Product has a qty required (SelectorQty)
Each orderline may be scheduled over various dates with ShipETA &
ShipQty

--------------------------------

Basically this page is to total metalwork used for each product on
order.

i.e. product A may be made of the following METALWORK CODES:
19 x 1 piece
30 x 1 piece

Product B
115 x 1 piece
67 x 1 piece
98 x 1 piece

Each product is assigned to an orderline of an order.
i.e. there may be an order for a customer of:

Product B x 10 (ShipQty)
product B requires the following metalwork
115 x 1 piece (this is Selector Name * SelectorQty)
67 x 1 piece
98 x 1 piece

so,

We require a total of
115 x 10 pieces (this is SelectorQty x ShipQty). ShipQty is the amount
of that product which uses code 115 for that particular order.

67 x 10 pieces
98 x 10 pieces

for this single orderline, but, the 10 x Product B required are split
over various scheduled dates. (ShipQty)
We may require 5 (ShipQty) this Friday and 5 (ShipQty) next Friday, but
i'm just interested in the total sum of all (SelectorQty x ShipQty) for
each Metal code.

So there will always be the same metalwork codes in the system, just
linked to different orders and quantities.

I need to write out all the metalwork codes, and print next to each one
the sum of all the different orders that uses that code

i.e.

for the above order we need
code 115 x 10 pieces

for another 30 orders we may also need code 115 in various other
quantities, which need to be totalled up.

Your dictionary code listed all the metal codes correctly and some of
the figures were even correct, but only 6 out of about 15 tested, so
something is still wrong somewhere.

I am using the following SQL statement:

-----------------------

strQuery = "SELECT metalselector.SelectorName, SUM(SelectorQty*ShipQty)
AS TotalMW, metalselector.SelectorQty, Customers.CustomerName,
OrderLines.JobNumber, Orders.PONumber, OrderLines.OrderQuantity,
Sum(StockMovements.QtyShipped) AS SumOfQtyShipped,
OrderQuantity-Sum(QtyShipped) AS RemainingUnits, OrderLines.OrderNotes,
Products.ProductRangeID, OrderLines.SelectAll, PCBForecast.ShipQty,
Products.ProdCode, PCBForecast.HeldMarker, Products.ProductID,
PCBForecast.ShipETA"

strQuery = strQuery & " FROM ((Customers INNER JOIN (Orders INNER JOIN
(Products INNER JOIN (OrderLines INNER JOIN StockMovements ON
OrderLines.JobNumber = StockMovements.JobNumber) ON (Products.ProductID
= OrderLines.ProductID) AND (Products.ProductID =
OrderLines.ProductID)) ON Orders.OrderID = OrderLines.OrderID) ON
Customers.CustomerID = Orders.CustomerID) INNER JOIN PCBForecast ON
OrderLines.JobNumber = PCBForecast.JobNumber) INNER JOIN metalselector
ON Products.ProductID = metalselector.ProductID"

strQuery = strQuery & " GROUP BY metalselector.SelectorName,
Customers.CustomerName, OrderLines.JobNumber, Orders.PONumber,
OrderLines.OrderQuantity, OrderLines.OrderNotes,
Products.ProductRangeID, OrderLines.SelectAll, PCBForecast.ShipQty,
Products.ProdCode, PCBForecast.HeldMarker, Products.ProductID,
PCBForecast.ShipETA, metalselector.SelectorQty"

strQuery = strQuery & " HAVING ((OrderQuantity-Sum(QtyShipped)>=0) AND
(OrderLines.SelectAll=-1) AND (PCBForecast.HeldMarker='Scheduled'))"

strQuery = strQuery & " ORDER BY SelectorName;"

Set RS = adoDataConn.Execute(strQuery)

-------------------------------

Your code gives me a resulting list as, in metalwork (SelectorName
order)
But most of the figures are incorrect.

1 = 2220
2 = 2668
3 = 18
4 = 9
5 = 27
6 = 300
7 = 420
8 = 933
9 = 264
10 = 18
11 = 460
12 = 31
19 = 3
20 = 3
Thanks
David

-------------------------------------------------------------
Ray Costanzo [MVP] wrote:
Can you explain the database design and show the code that you're using now
to get the data?

Ray at work

"David" <da*********@scene-double.co.ukwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
Ray,

Thanks for the reply,

The page worked with your code, but i'm not exactly sure how or what it
produced:
It displayed the first field in my SQL (customername) and then = a
number, for each customer.

I need it to list , SelectorName (A) = sum of qty for SelectorName A
etc

Please can you explain further ?

Thanks

-------------------------------------------------------------------------------------------------------

Ray Costanzo [MVP] wrote:
I'd think that you could do this at the database level, but it's hard to
say
without seeing the database. So, for a code solution, this may be one of
the rare instances that a dictionary object comes into use.

Dim oDict
Set oDict = CreateObject("Scripting.Dictionary")
Do While Not yourRecordset.EOF
sKey = yourRecordset.Fields.Item(0).Value
sValue = yourRecordset.Fields.Item(1).Value

If oDict.Exists(sKey) Then
oDict(sKey) = CLng(oDict(sKey)) + CLng(sValue)
Else
oDict(sKey) = sValue
End If
yourRecordset.MoveNext
Loop

For Each oKey in oDict.Keys
Response.Write oKey & " = " & oDict(oKey) & "<br />"
Next
Set oDict = Nothing

Ray at work


"David" <da*********@scene-double.co.ukwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi,

I have an asp page which prints data as follows:
The sum in brackets is a calculated result on the page, SQ *
RS2("SelectorQty"), a variable SQ which holds a qty multiplied by a
record value

96 (50)
104 (50)
96 (100)
104 (100)
96 (100)
104 (100)
96 (100)

What I want to be able to do is print the page like this:

96 = 350 (where 350 is the sum of all items displayed as 96)
104 = 350 (where 350 is the sum of all items displayed as 104)

I would be very grateful for any help on this.
I cannot work out how to group or sum in the query as I have the first
SQL statement pulling data, then a second within the loop pulling the
number 96 & 104, then a calculation with done between data from both
SQL statements.

Thanks
Sep 25 '06 #5
No worries, i've fixed it hopefully, the problem was to do with using
sum in the SQL.
Your code works a treat ..... even though I have never used this
object, .... cool... nice one !

David wrote:
Thanks Ray,

Each customer has many orders
Each order has many orderlines
Each orderline has 1 product
Each product has 1 or more MetalCodes (SelectorNames)
Each SelectorName for that Product has a qty required (SelectorQty)
Each orderline may be scheduled over various dates with ShipETA &
ShipQty

--------------------------------

Basically this page is to total metalwork used for each product on
order.

i.e. product A may be made of the following METALWORK CODES:
19 x 1 piece
30 x 1 piece

Product B
115 x 1 piece
67 x 1 piece
98 x 1 piece

Each product is assigned to an orderline of an order.
i.e. there may be an order for a customer of:

Product B x 10 (ShipQty)
product B requires the following metalwork
115 x 1 piece (this is Selector Name * SelectorQty)
67 x 1 piece
98 x 1 piece

so,

We require a total of
115 x 10 pieces (this is SelectorQty x ShipQty). ShipQty is the amount
of that product which uses code 115 for that particular order.

67 x 10 pieces
98 x 10 pieces

for this single orderline, but, the 10 x Product B required are split
over various scheduled dates. (ShipQty)
We may require 5 (ShipQty) this Friday and 5 (ShipQty) next Friday, but
i'm just interested in the total sum of all (SelectorQty x ShipQty) for
each Metal code.

So there will always be the same metalwork codes in the system, just
linked to different orders and quantities.

I need to write out all the metalwork codes, and print next to each one
the sum of all the different orders that uses that code

i.e.

for the above order we need
code 115 x 10 pieces

for another 30 orders we may also need code 115 in various other
quantities, which need to be totalled up.

Your dictionary code listed all the metal codes correctly and some of
the figures were even correct, but only 6 out of about 15 tested, so
something is still wrong somewhere.

I am using the following SQL statement:

-----------------------

strQuery = "SELECT metalselector.SelectorName, SUM(SelectorQty*ShipQty)
AS TotalMW, metalselector.SelectorQty, Customers.CustomerName,
OrderLines.JobNumber, Orders.PONumber, OrderLines.OrderQuantity,
Sum(StockMovements.QtyShipped) AS SumOfQtyShipped,
OrderQuantity-Sum(QtyShipped) AS RemainingUnits, OrderLines.OrderNotes,
Products.ProductRangeID, OrderLines.SelectAll, PCBForecast.ShipQty,
Products.ProdCode, PCBForecast.HeldMarker, Products.ProductID,
PCBForecast.ShipETA"

strQuery = strQuery & " FROM ((Customers INNER JOIN (Orders INNER JOIN
(Products INNER JOIN (OrderLines INNER JOIN StockMovements ON
OrderLines.JobNumber = StockMovements.JobNumber) ON (Products.ProductID
= OrderLines.ProductID) AND (Products.ProductID =
OrderLines.ProductID)) ON Orders.OrderID = OrderLines.OrderID) ON
Customers.CustomerID = Orders.CustomerID) INNER JOIN PCBForecast ON
OrderLines.JobNumber = PCBForecast.JobNumber) INNER JOIN metalselector
ON Products.ProductID = metalselector.ProductID"

strQuery = strQuery & " GROUP BY metalselector.SelectorName,
Customers.CustomerName, OrderLines.JobNumber, Orders.PONumber,
OrderLines.OrderQuantity, OrderLines.OrderNotes,
Products.ProductRangeID, OrderLines.SelectAll, PCBForecast.ShipQty,
Products.ProdCode, PCBForecast.HeldMarker, Products.ProductID,
PCBForecast.ShipETA, metalselector.SelectorQty"

strQuery = strQuery & " HAVING ((OrderQuantity-Sum(QtyShipped)>=0) AND
(OrderLines.SelectAll=-1) AND (PCBForecast.HeldMarker='Scheduled'))"

strQuery = strQuery & " ORDER BY SelectorName;"

Set RS = adoDataConn.Execute(strQuery)

-------------------------------

Your code gives me a resulting list as, in metalwork (SelectorName
order)
But most of the figures are incorrect.

1 = 2220
2 = 2668
3 = 18
4 = 9
5 = 27
6 = 300
7 = 420
8 = 933
9 = 264
10 = 18
11 = 460
12 = 31
19 = 3
20 = 3
Thanks
David

-------------------------------------------------------------
Ray Costanzo [MVP] wrote:
Can you explain the database design and show the code that you're using now
to get the data?

Ray at work

"David" <da*********@scene-double.co.ukwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
Ray,
>
Thanks for the reply,
>
The page worked with your code, but i'm not exactly sure how or what it
produced:
It displayed the first field in my SQL (customername) and then = a
number, for each customer.
>
I need it to list , SelectorName (A) = sum of qty for SelectorName A
etc
>
Please can you explain further ?
>
Thanks
>
-------------------------------------------------------------------------------------------------------
>
>
>
Ray Costanzo [MVP] wrote:
>I'd think that you could do this at the database level, but it's hard to
>say
>without seeing the database. So, for a code solution, this may be one of
>the rare instances that a dictionary object comes into use.
>>
>Dim oDict
>Set oDict = CreateObject("Scripting.Dictionary")
>>
>>
>Do While Not yourRecordset.EOF
> sKey = yourRecordset.Fields.Item(0).Value
> sValue = yourRecordset.Fields.Item(1).Value
>>
> If oDict.Exists(sKey) Then
> oDict(sKey) = CLng(oDict(sKey)) + CLng(sValue)
> Else
> oDict(sKey) = sValue
> End If
> yourRecordset.MoveNext
>Loop
>>
>For Each oKey in oDict.Keys
> Response.Write oKey & " = " & oDict(oKey) & "<br />"
>Next
>Set oDict = Nothing
>>
>Ray at work
>>
>>
>>
>>
>"David" <da*********@scene-double.co.ukwrote in message
>news:11**********************@m73g2000cwd.googleg roups.com...
Hi,
>
I have an asp page which prints data as follows:
The sum in brackets is a calculated result on the page, SQ *
RS2("SelectorQty"), a variable SQ which holds a qty multiplied by a
record value
>
96 (50)
104 (50)
96 (100)
104 (100)
96 (100)
104 (100)
96 (100)
>
What I want to be able to do is print the page like this:
>
96 = 350 (where 350 is the sum of all items displayed as 96)
104 = 350 (where 350 is the sum of all items displayed as 104)
>
I would be very grateful for any help on this.
I cannot work out how to group or sum in the query as I have the first
SQL statement pulling data, then a second within the loop pulling the
number 96 & 104, then a calculation with done between data from both
SQL statements.
>
Thanks
>
>
Sep 25 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: cjm | last post by:
I need to group records and assign a setid to the group. I have a table with data that looks like this ColA ColB 94015 01065 94016 01065 94015 01085 94015 01086 33383 00912 32601 00912
3
by: Graham | last post by:
Hi, I am having trouble getting XSL to count the members of a group. What I am trying to do is group by <objectid.Contactid> and count the number of <activityid>'s for each <objectid.contactid>....
5
by: Mike King | last post by:
I don't know how to group the following data in the way I want it. I want the output of the transformation to be "5678". Does anyone know what I am doing worry? <?xml version="1.0"?> <data>...
3
by: ahaque38 | last post by:
Hello. Using A2K SP3, I am having the following problem with a report using "Sorting and Grouping". I have recently added a grouping in the reports for "Category2<>'CONTRACTS'". I have...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
12
by: InvalidLastName | last post by:
We have been used XslTransform. .NET 1.1, for transform XML document, Dataset with xsl to HTML. Some of these html contents contain javascript and links. For example: // javascript if (a &gt; b)...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
by: Sandeep Singh | last post by:
Hi, How to do group by in XSLT ? I tried on the following codes: <files> <file name="swablr.eps" size="4313" project="mars"/> <file name="batboy.wks" size="424" ...
0
by: Leira | last post by:
Hi, I have a problem with grouping. My source XML has <record> elements that have a @name and a @group attribute. It looks something like this: <root> <result> <record name="test1"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.