Question : How do i group and sum alphabet?

I have a list of examination result data (as per image attachment). The problem is the grade is a combination of alphabet & numeric (1A, 2A, 3B, 4B, 5C, 6C, 7D, 8E, 9G) and I need to group it as follows:

1A & 2A = A
3B & 4B = B
5C & 6C = C
7D = D
8E = E
9G = G

and combine the total result. I have no idea whether I need to do it in SQL query or ASP codes. Ideas & helps are much appreciated :)

Answer : How do i group and sum alphabet?

Ok, here is the finished code that I tested with the table you sent:
Just put the code in a module and you can call it from a query, like:

Select Distinct students, GetGrades([students]) as GradeList from result;
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
Function GetGrades(lngStudentID As Long) As String
Dim rst As DAO.Recordset
Dim strResult As String
Dim strLastGrade As String
Dim strSQL As String
Dim strDelim As String
 
    strSQL = "SELECT Right$([Grade],1) AS GradeLetter, Count(Students) AS GradeCount From " & _
            "(Select Students, Subject1 as Grade From result " & _
                " Union All Select Students, Subject2 as Grade From result " & _
                " Union All Select Students, Subject3 as Grade From result " & _
                " Union All Select Students, Subject4 as Grade From result " & _
                " Union All Select Students, Subject5 as Grade From result " & _
            ") as qry " & _
            "Where students = " & lngStudentID & _
            " GROUP BY Right$([Grade],1)"
    Set rst = CurrentDb.OpenRecordset(strSQL)
    strResult = "":  strDelim = ""
    While Not rst.EOF
        strResult = strResult & strDelim & rst!GradeCount & rst!GradeLetter
        strDelim = ","
        rst.MoveNext
    Wend
    
    GetGrades = strResult
  
End Function
Open in New Window Select All
Random Solutions  
 
programming4us programming4us