Summing columns in a Dynamic Table ??

# Thread: Summing columns in a Dynamic Table ??

1. Paul M Guest

## Summing columns in a Dynamic Table ??

I have a query that produces a dynamic table from the results ( not a problem ), but I want to be able to place a total at the bottom of sum of the columns. which is where I come unstuck ! <BR>This is the code I am using at the moment: <BR>&#039 -- output the contents <BR>pintotal = "" <BR><BR>Response.Write "&#060;TR&#062;" <BR>For i = 0 to objRS.Fields.Count - 1 <BR>If Ucase(objRS.Fields(i).Name) = "PIN" Then <BR>Response.Write "&#060;TD&#062;&#060;FONT FACE=""ARIAL"" SIZE=""1""&#062;&#060;A HREF=""drilldown2.asp?pin=" _ <BR>& objRS.Fields(i) & """&#062;" & objRS.Fields(i) & "&#060;/A&#062;&#060;/TD&#062;" <BR><BR>Elseif Ucase(objRS.Fields(i).Name) = "PSHORT" Then <BR>Response.Write "&#060;TD&#062;&#060;FONT FACE=""ARIAL"" SIZE=""1""&#062;" & objRS.Fields(i) & "%" & "&#060;/A&#062;&#060;/font&#062;&#060;/TD&#062;" <BR><BR>Elseif Ucase(objRS.Fields(i).Name) = "CALLS ANSWERED" Then <BR>Response.Write "&#060;TD&#062;&#060;FONT FACE=""ARIAL"" SIZE=""1""&#062;" & objRS.Fields(i) & "&#060;/FONT&#062;&#060;/TD&#062;" <BR>pintotal = pintotal + objRS.fields(i) <BR><BR>Else <BR>Response.Write "&#060;TD&#062;&#060;FONT FACE=""ARIAL"" SIZE=""1""&#062;" & objRS.Fields(i) & "&#060;/FONT&#062;&#060;/TD&#062;" <BR><BR>End if <BR><BR>Next <BR>Response.write "&#060;/TR&#062;" <BR>&#039 -- move to the next record <BR>objRS.MoveNext <BR><BR>This only gives me the value for the last entry in the Column labelled CALLS ANSWERED. Is the right approach to go with a CASE statement to identify the columns, as I don&#039t want to total all the columns I am returning. Any help would be apprecaited. <BR><BR>Paul M <BR>

2. Senior Member
Join Date
Dec 1969
Posts
1,944

## RE: Summing columns in a Dynamic Table ??

Hi,<BR><BR>It&#039s simple.<BR>You are dynamically generating only the table.not the database<BR>values.So just query the column you want for the total, and then<BR>display it right below the corresponding column in the table you<BR>generated dynamically.<BR><BR>Sreenivas

3. Paul M Guest

## RE: Summing columns in a Dynamic Table ??

Thankyou for this Sreenivas, <BR>Could you supply a rough code sample, as I.<BR>a: haven&#039t tried this before, and<BR>b: am not sure that I understand what you mean.<BR><BR>Thankyou if you can Help !<BR><BR>Paul M

4. Senior Member
Join Date
Dec 1969
Posts
1,944

## RE: Summing columns in a Dynamic Table ??

write the query like<BR>set Rs=Conn.Execute("select sum(col.name) form abc")<BR>now you will have the sum of the column you want in Rs(0)<BR><BR>so just use it whereever you want to display like<BR>&#060;td&#062;&#060;%=Rs(0)%&#062;&#060;/td&#062;<BR><BR>sree

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•