SQL "SUM" function mystery

Results 1 to 3 of 3

Thread: SQL "SUM" function mystery

  1. #1
    Bill Anthony Guest

    Default SQL "SUM" function mystery

    Greetings fellow developers:<BR><BR>I would like to address the group to find someone who might be able to help me.<BR><BR>What I am trying to accomplish is to issue a SQL SELECT statement which uses the SUM function in order to return the sum of all values recorded within a certain attribute having specified conditions. I have a table that contains simple numeric values on what our support team does in service calls and work requests. The table is called "Monthly Activity"; the work requests attribute is called "DeskWR". We have many other attributes that we are tracking.<BR><BR>The SQL statement is somewhat like the following:<BR><BR> sql = "SELECT [Monthly Activity].Year, [Monthly Activity].Qtr, Sum([Monthly Activity].DeskWR) AS sDeskWR FROM [Monthly Activity] WHERE ((([Monthly Activity].Year)=" & Request.Form("year") & ") AND (([Monthly Activity].Qtr)=" & Request.Form("qtr") & ")) "<BR><BR>I am attempting to gather all records with, for example, "1999" as the year and, say, "2" as the quarter (referencing Apr, May, Jun). Then, I am taking the sum of all instances of "DeskWR" to obtain the sum for the specified quarter.<BR><BR>The SQL statement seems to work because I do not receive any errors. My question is, shouldn&#039t I be able to script:<BR><BR>&#060;%=sDeskWR%&#062;<BR><BR>to get the value in my ASP page?<BR><BR>Currently, I get absolutely nothing when I script the container. Why does this happen? What am I missing? Is there an easier way to calculate sums of a given attribute?<BR><BR>I appreciate anyone&#039s help and expertise, as always.<BR><BR>Bill Anthony

  2. #2
    Nathen Grass Guest

    Default RE: SQL

    The value you want is in a Recordset object so to get the value you would use:<BR><BR>&#060;%= objRS("sDeskWR")%&#062;<BR><BR>where objRS is the name of you recordset object.

  3. #3
    Bill Anthony Guest

    Default RE: SQL

    Thanks very much Nathen!<BR><BR>Sheesh! I can&#039t believe I forgot to reference the recordset!<BR>I guess four eyes are certainly better than two. I do appreciate your help.<BR><BR>Bill Anthony

Posting Permissions

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