dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Speeding up a Ranking Formula

  1. #1
    Join Date
    Dec 2010
    Posts
    17

    Speeding up a Ranking Formula

    Does anyone know how I can speed up a Ranking query? Iím currently using the formula below:

    Rank: (Select count(*) from qryCustomerTotals1 as B where qryCustomerTotals1.CustomerTotal > B.customerTotal)

    From reading on the web, some people talk about doing it in a modules, they even give some examples (see below)

    Iím just learning access, and have come a long way with all your help. I sure could use some advice with this one.

    I donít even one where to begin putting together the code below.

    Thanks for taking the time to help a new access guy.
    Code:
    The complete code is:
    
    Option Compare Database
    Dim lngLastPoints As Long
    Dim lngLastRank As Long
    Dim lngRankInc As Long
    
    Function RankFunction(lngPoints As Long) As Long
    
    lngLastPoints = 0
    
    If lngLastPoints = lngPoints Then
       RankFunction = lngLastRank
        lngRankInc = lngRankInc + 1
        lngLastPoints = lngPoints
    Else
         lngRankInc = lngRankInc + 1
         RankFunction = lngRankInc
         lngLastRank = lngRankInc
         lngLastPoints = lngPoints
    End If
    End Function
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Speeding up a Ranking Formula

    Don't use Select *, use only the fields that you need.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,324

    Re: Speeding up a Ranking Formula

    Also it will be faster if your fields on the where side of the query are part of an index.
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    Re: Speeding up a Ranking Formula

    Post the query you have written for finding the rank, there will always room for fine tuning!!
    Encourage the efforts of fellow members by rating

    Lets not Spoon Feed and create pool of lazy programmers

    - ComIT Solutions

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)