|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Problems with SQL statement
Hi guys, I posted a similar thread to this on another forum however I've made some progress since. I want to be able to write the names of the 4 teams with the highest Points total to file. Any ideas? Im stuck on the SQL command.
The table is called League, field containing team names = Team, field containing points = Points. Many thanks, David [vb]Option Explicit Dim cn As ADODB.Connection Dim rs As ADODB.Recordset Private Sub Form_Load() Set cn = New ADODB.Connection 'cnHome Set rs = New ADODB.Recordset 'rsHome Dim strFile As String Dim sSQL As String strFile = "yourdb.mdb" sSQL = "SELECT * FROM League WHERE Points....." cn.ConnectionString = strFile 'open the ADO connection and recordset cn.Provider = "Microsoft.Jet.OLEDB.4.0" cn.Open cn.Properties("Jet OLEDB:Max Buffer Size") = 256 rs.Open sSQL, cn 'Do While Not rs.EOF 'Loop 'rs.MoveNext End Sub Private Sub cmdGet_Click() Open App.Path + "/Retrieve.txt" For Output As #1 Print #1, rs("Team") Close #1 End Sub Private Sub Form_Unload(Cancel As Integer) 'Close connection and recordset and destroy them rs.Close Set rs = Nothing cn.Close Set cn = Nothing End Sub[/vb] |
|
#2
|
||||
|
||||
|
select top 4 team,sum(points) as totalpoints
from league group by team order by sum(points) desc |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > Problems with SQL statement |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|