Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 429
  • Last Modified:

Setting RowCount

Is there a way to limit the amount of records that are returned by a recordset? Can i set the rowcount in the query and then the RS will only return that amount of records.
0
Coates
Asked:
Coates
  • 3
  • 2
1 Solution
 
watyCommented:
Here is a sample :

SELECT TOP 25
FirstName, LastName
FROM Students
WHERE GraduationYear = 1997
ORDER BY GradePointAverage DESC;
0
 
CoatesAuthor Commented:
What does the DESC mean?
0
 
watyCommented:
It means that all the record will be sorted descently.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
CoatesAuthor Commented:
Ive tried this using telnet to my sybase server, and i get a syntax error near '25'. I dont think my version of sybase supports that method.
0
 
CoatesAuthor Commented:
Ive tried this using telnet to my sybase server, and i get a syntax error near '25'. I dont think my version of sybase supports that method.
0
 
BlackAndWhiteCommented:
It depends on what you are using

1. If you are using rdo with an rdoQuery
---------------------------------------------------
    Dim env As rdoEnvironment
    Dim db As rdoConnection
    Dim qd As rdoQuery
    Dim rs As rdoResultset
   
    Set env = rdoEnvironments(0)
    Set db = env.OpenConnection(dsName:="MYDSN", Connect:=".......")
    Set qd = db.CreateQuery(Name:="tmp", sqlString:="Select * from Products")
    qd.MaxRows = 10
    Set rs = qd.OpenResultset(rdOpenStatic)
   
    'Now rs should have been restricted to 10 recs.,.

2. If you are using DAO here is a sample from the help using CacheSize
---------------------------------------------------

Sub ClientServerX3()

      Dim dbsCurrent As Database
      Dim tdfRoyalties As TableDef
      Dim rstRemote As Recordset
      Dim sngStart As Single
      Dim sngEnd As Single
      Dim sngNoCache As Single
      Dim sngCache As Single
      Dim intLoop As Integer
      Dim strTemp As String
      Dim intRecords As Integer

      ' Open a database to which a linked table can be
      ' appended.
      Set dbsCurrent = OpenDatabase("DB1.mdb")

      ' Create a linked table that connects to a Microsoft SQL
      ' Server database.

Set tdfRoyalties = _
            dbsCurrent.CreateTableDef("Royalties")
      tdfRoyalties.Connect = _
            "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers"
      tdfRoyalties.SourceTableName = "roysched"
      dbsCurrent.TableDefs.Append tdfRoyalties
      Set rstRemote = _
            dbsCurrent.OpenRecordset("Royalties")

      With rstRemote
            ' Enumerate the Recordset object twice and record
            ' the elapsed time.
            sngStart = Timer

            For intLoop = 1 To 2
                  .MoveFirst

Do While Not .EOF
                        ' Execute a simple operation for the
                        ' performance test.
                        strTemp = !title_id
                        .MoveNext
                  Loop
            Next intLoop

            sngEnd = Timer
            sngNoCache = sngEnd - sngStart

            ' Cache the first 50 records.
            .MoveFirst
            .CacheSize = 50
            .FillCache
            sngStart = Timer

            ' Enumerate the Recordset object twice and record
            ' the elapsed time.
            For intLoop = 1 To 2
                  intRecords = 0

MoveFirst
                  Do While Not .EOF
                        ' Execute a simple operation for the
                        ' performance test.
                        strTemp = !title_id
                        ' Count the records. If the end of the
                        ' cache is reached, reset the cache to the
                        ' next 50 records.
                        intRecords = intRecords + 1
                        .MoveNext
                        If intRecords Mod 50 = 0 Then
                              .CacheStart = .Bookmark
                              .FillCache
                        End If
                  Loop
            Next intLoop

sngEnd = Timer
            sngCache = sngEnd - sngStart

            ' Display performance results.
            MsgBox "Caching Performance Results:" & vbCr & _
                  "    No cache: " & Format(sngNoCache, _
                  "##0.000") & " seconds" & vbCr & _
                  "    50-record cache: " & Format(sngCache, _
                  "##0.000") & " seconds"
            .Close
      End With

      ' Delete linked table because this is a demonstration.
      dbsCurrent.TableDefs.Delete tdfRoyalties.Name
      dbsCurrent.Close

End Sub

0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now