Solved

Select Sum(Numeric-Col-Name)

Posted on 2014-12-25
10
121 Views
Last Modified: 2014-12-25
Hi All (Merry Christmas)

I am trying to load an array in Classic asp as follows:

strSQL = "SELECT HS_ID, " &_
             "HS_Stu_ID, " &_  
             "SUM(HS_Score) " &_
         "FROM tbl_HomwWork_Scores WHERE HS_Week_ID <= 13 AND HS_Class_ID = " & NumClassID & " Order By HS_Score DESC;"
Set rsData = MyConn.Execute(strSQL)
If Not rsData.EOF Then
ArrTermOneScores = rsData.GetRows()
rsData.Close
End If

Getting an error 'Microsoft JET Database Engine error '80040e21'

Its in Spanish (Ha intentado ejecutar una consulta que no incluye la expresión especificada 'HS_ID' como parte de una función de agregado. )

Any ideas would be appreciated. I do not get the error if I remove the Sum() and just call the col.

I shall be back later.

Kind regards
0
Comment
Question by:Abiel de Groot
  • 5
  • 4
10 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40517564
If you are doing a SUM you need to have a GROUP BY - on some common value otherwise how is it to know which rows to sum
I assume you would want to be grouping by HS_Stu_ID
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 40517568
You need to group by any column not contained in a aggregate function like SUM.
Insert the following before ORDER BY:
group by HS_ID, HS_Stu_ID

Open in new window

0
 
LVL 5

Author Comment

by:Abiel de Groot
ID: 40517899
Ok, that makes sense. ;-)

I now have this

strSQL = "SELECT SUM(HS_Score) Group by HS_Stu_ID " &_
         "FROM tbl_HomwWork_Scores WHERE HS_Week_ID <= 13 AND HS_Class_ID = " & NumClassID & " Order By HS_Score DESC;"
Set rsData = MyConn.Execute(strSQL)
If Not rsData.EOF Then
ArrTermOneScores = rsData.GetRows()
rsData.Close
End If

Getting this error:

Microsoft JET Database Engine error '80040e14'

Error de sintaxis (falta operador) en la expresión de consulta 'SUM(HS_Score) Group by HS_Stu_ID'.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40517913
strSQL = "SELECT SUM(HS_Score), HS_Stu_ID " &_
          "FROM tbl_HomwWork_Scores WHERE HS_Week_ID <= 13 AND HS_Class_ID = " & NumClassID & " GROUP BY HS_Stu_ID Order By HS_Score DESC;"

Open in new window

0
 
LVL 5

Author Comment

by:Abiel de Groot
ID: 40517917
Hi Gary, I really appreciate your help. I tried your code and I get this error.

Microsoft JET Database Engine error '80040e21'

Ha intentado ejecutar una consulta que no incluye la expresión especificada 'HS_Score' como parte de una función de agregado.

PS. This is running against an Access DB

Kind regards
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 5

Author Comment

by:Abiel de Groot
ID: 40517921
This is the design view of the table.

A
EE-01.jpg
0
 
LVL 58

Expert Comment

by:Gary
ID: 40517923
strSQL = "SELECT SUM(HS_Score) as total_score, HS_Stu_ID " &_
          "FROM tbl_HomwWork_Scores WHERE HS_Week_ID <= 13 AND HS_Class_ID = " & NumClassID & " GROUP BY HS_Stu_ID Order By total_score DESC;"

Open in new window

0
 
LVL 5

Author Comment

by:Abiel de Groot
ID: 40517931
Almost !

If I run as you gave it, it throws an error:

Microsoft JET Database Engine error '80040e10'
No se han especificado valores para algunos de los parámetros requeridos.

However, if I remove the 'Order By total_score DESC' it then works. ;-(

I do need the array to be ordered by the scores...

A
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40517938
MySQL is my db of choice, haven't used Access in years and it seems a bit weird with these type of scenarios

strSQL = "SELECT SUM(HS_Score) as total_score, HS_Stu_ID " &_
          "FROM tbl_HomwWork_Scores WHERE HS_Week_ID <= 13 AND HS_Class_ID = " & NumClassID & " GROUP BY HS_Stu_ID Order By SUM(HS_Score) DESC;"

Open in new window

0
 
LVL 5

Author Comment

by:Abiel de Groot
ID: 40517951
That worked. Many Thanks.

A
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now