#1
  1. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2004
    Posts
    42
    Rep Power
    11

    Select Case question


    Just a quick question from a relative newbie.

    Is there a way to write this Case Select dynamically?

    Code:
    Calls1 = 0
    Calls2 = 0
    Calls3 = 0
    
    While not rs.eof
    
    		If Rs("Representative") = "Jo Bonner" Then   
    		Calls1 = (Calls1 + rs("Calls"))
    End if
    		If Rs("Representative") = "Martha Roby" Then   
    		Calls2 = (Calls2 + rs("Calls"))
    End if
    		If Rs("Representative") = "Mike Rogers" Then   
    		Calls3 = (Calls3 + rs("Calls"))
    End if
       Rs.Movenext
    Wend
    Rs.MoveFirst
    With this in the spot to view the call totals.
    Code:
    <% = Calls1 %>
    <% = Calls2 %>
    <% = Calls3 %>
    I am writing a page that lists a total for all telephone calls to all 435 US Representatives...by state. I don't want to have to write this case select 435 times...but I'm just new enough at this that I'm not sure how to do it dynamically.

    I thought about:

    Code:
    If Rs(“Representative”) = “ ' " & request("Representative") & " ' ” Then   
    		Calls = (Calls + rs("Calls"))
    End if
    But, that doesn't work. I think I'm close, but not really sure. Does anyone feel up to teaching a little today?

    Thanks in advance
    Jackson
  2. #2
  3. No Profile Picture
    Contributing User
    ASP High Scholar (3500 - 3999 posts)

    Join Date
    Jan 2007
    Location
    Indianapolis, USA
    Posts
    3,559
    Rep Power
    697
    Why not do you calculations in your SQL statement?

    Code:
    SELECT COUNT(Calls) As NumCalls FROM MyTable
    You can then loop through your SELECT and write out the number of calls for each person.
    "You'll never be as perfect as BLaaaaaaaaarche."

Similar Threads

  1. Select and sum question
    By Jens Simonsen in forum ASP Development
    Replies: 2
    Last Post: December 28th, 2006, 08:17 AM
  2. Select top 1 question
    By miniskirt in forum ASP Development
    Replies: 9
    Last Post: June 6th, 2006, 01:21 AM
  3. Select * From question
    By Levurax in forum Microsoft SQL Server
    Replies: 4
    Last Post: April 25th, 2006, 12:52 PM
  4. question regarding select statement
    By lee82 in forum ASP Development
    Replies: 1
    Last Post: November 5th, 2004, 07:23 AM
  5. select question
    By webb in forum ASP Development
    Replies: 2
    Last Post: October 11th, 2004, 03:53 PM

IMN logo majestic logo threadwatch logo seochat tools logo