SQL - count() and sum()

Results 1 to 5 of 5

Thread: SQL - count() and sum()

  1. #1
    Reggie Guest

    Default SQL - count() and sum()

    How do I access the numbers that these functions generate?<BR><BR>For example if I use:<BR>SELECT COUNT(*) FROM myTable;<BR>or<BR>SELECT SUM() FROM myTable;<BR><BR>how can I output what the sum is?<BR>Response.write .....what goes here.....<BR><BR>Thanks

  2. #2
    Haroon Qureshi Guest

    Default RE: SQL - count() and sum()

    Try<BR><BR>Select Count() As tCount From FILENAME<BR>or <BR>Select SUM(DEBIT) As tDebit From FILENAME<BR><BR>Use tCount & tDebit for result<BR>Thanks

  3. #3
    Reggie Guest

    Default RE: SQL - count() and sum()

    I still can&#039;t quite get it to work.<BR><BR>I am using:<BR>&#060;%<BR>count_query = "Select Count(*) as tCount from Survey"<BR>MyConn.execute(count_query)<BR>Response .write tCount<BR>%&#062;<BR><BR>It doesn&#039;t give an error, but it also doesn&#039;t print anything.<BR>If I use Count() I get an error that says &#039;Count() requires a parameter&#039;. If I use an actual field name like Count(ID), it does the same thing as the Count(*).

  4. #4
    Join Date
    Dec 1969

    Default Where is your recordset

    You need a recordset<BR>&#060;%<BR>count_query = "Select Count(*) as tCount from Survey"<BR>set rs = MyConn.execute(count_query)<BR>Response.write rs("tCount")<BR>%&#062;<BR><BR><BR>Tidbit of useless information:<BR>Count(*) and Count(column) may return dissimilar result depending on what data you have in the table. This is because count(column) will discard null values from the count. <BR>

  5. #5
    Reggie Guest

    Default RE: Where is your recordset

    I eliminated my db connection stuff at the top because I didn&#039;t think it was relevant.<BR><BR>Here is what I finally got working. Seems like a lot of code, but oh well, it does the job.<BR>&#060;%<BR>Set MyConn = Server.CreateObject("ADODB.Connection")<BR>MdbFile Path = Server.MapPath("survey.mdb")<BR>MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"<BR><BR>Set countRS = MyConn.execute("Select Count(ID) as totalRecords from Survey")<BR>countAll = countRS("totalrecords")<BR>Response.write countAll<BR>%&#062;

Posting Permissions

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