Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Adding multiple fields with ASP & SQL

Community Beginner ,
Sep 03, 2010 Sep 03, 2010

Hi there --

I have a database that holds subscription info. Based on the time of payment and the length of subscription, I calculate an accrued monthly amount, assign that amount to a variable, and assign it to a month on a Web page.

I want to tally up the totals for the columns that result. That means I'll need to add up several fields per record, and also add up all the records - like this:

Customer 1: Field 1 + Field 2 + Field 3

Customer 2: Field 1 + Field 2 + Field 3

... and so on - I want all those fields added together.

I can get what looks like the last record's fields summed by using <% = (Field1) + (Field2) + (Field3) %> but it doesn't tally up all the records.

It's possible to do, isn't it? Help?

Thanks!

TOPICS
Server side applications
667
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 03, 2010 Sep 03, 2010

If you are outputting all rows in a loop, then you can create variables to keep a running total. If you only ouput the totals, then total them within your SQL statement.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 03, 2010 Sep 03, 2010

Thank you!

I am looping through the recordset. Can you tell me how I'd handle those variables? I can't quite get my head around it.

Fields 1, 2 and 3 are already variables calculated from the values in the database, and they're getting output into that recordset loop...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 03, 2010 Sep 03, 2010
LATEST

Create a variable(s) outside the loop. Then for every iteration, add the values of the columns of interest to the variable(s). When the loop is complete, output the value of those variables. That's it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines