user3850947
user3850947

Reputation: 1

SQL and VBScript

I want to show the quantity and Lbs purchased per customer on a web page without showing duplicate customers. The output value of total lbs is derived from retrieving the total lb in that type of package i.e. 6 for a 6 lbs per package, then in VBScript multiplying it by the quantity in that row.

<% Customer = ("CustomerName")
Qty = ("Qty")
ItemLbs = ("Lbs") * Qty
%>

It works fine without SUMing the customer names but when the duplicate customer names are SUMed the VB equation outputs incorrect information.

I would Like to corect this either via VBScript or SQL

Upvotes: 0

Views: 67

Answers (1)

Bond
Bond

Reputation: 16311

Use GROUP BY and have SQL do it for you:

SELECT CustomerName,sum(qty*lbs) AS TotalWeight FROM yourtable GROUP BY CustomerName

Upvotes: 1

Related Questions