• cengland0 (1/6/2011)


    There are several ranking functions:

    RANK

    DENSE_RANK

    NTILE

    ROW_NUMBER

    Yes, there are several. However, this question is about the RANK() function, so why even bring these others into the mix?

    When the question asked will it always return consecutive integers, I knew right away that it was false because none of them will always return consecutive integers if there is only one row. One row is still a non empty rowset but that was not explained in the provided explanation.

    Are you just trying to find fault with the question?

    A better argument would have been that all of the windowing functions accept a PARTITION BY clause, which re-starts the numbering - thus the results are not always sequential.

    However, sometimes you just have to go with what you know the author meant to convey.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2