Hi!
So, I have two tables, exam1 and exam2 which looks like these:
table:exam1
sid physics chemistry biology
3 80 60 40
table:exam2
sid physics chemistry biology
3 40 50 70
[b]Problem:[/b]
I want to find the sum of items from both tables (exam1 and exam2), like this
table: total
sid physics chemistry biology
3 120 110 110
[b]BUT:[/b]
I wont always have to find total of all courses (physics, chemistry, biology), sometimes I may want to find sum of only two, one of all three subjects, so this is really a variable.
Since I program from VB.NET, the list of courses to be totaled can be specified by a user at run time and is kept in a variable say, "courses", so sometimes courses= (physics,chemistry,biology) sometimes courses=(physics,chemistry) and so on.
How can I then find a total of courses that the user selects? (still total of courses in exam1+exam2 tables)
Thanks
What I have tried:
<pre lang="vb">
Dim courses As String = "physics,chemistry"
Dim cmd As New MySqlCommand
cmd.CommandText = "Select A.sid, (A." & LCase((courses)) & "+B." & LCase((courses)) &
") As " & courses & " From exam1 A Inner Join exam2 B On A.sid=B.sid Order By A.sid"
MsgBox("STATEMENT = " & cmd.CommandText)
cmd.Connection = con
Dim rd As MySqlDataReader = cmd.ExecuteReader()
If rd.HasRows() Then
Dim x As String
Do While rd.Read()
x &= String.Format("{0} {1}", rd("sid"), rd(ComboBox2.SelectedItem)) & vbCrLf
Loop
MessageBox.Show(x)
End If
rd.Close()
cmd.Dispose()
con.Dispose()