Ranking records in query results

  • Thanks folks... great feedback and I appreciate it very much.

    Ben, I've not found much on Triangular joins but I did write an explanation for someone else on this forum.  Please see the following URL...

    http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=338&messageid=359124&p=2

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thank you, everyone for your feedback! 

    I have considered myself an intermediate user for a while now, and this is totally greek to me.  But, I will walk through it and see what I come up with.

    The original reply may work.  However, my query that comes up with the simple records is a nested select statement that is grouped and has several fields that are summed, along with several case statements.  Not real sure how without using a cursor to get the data into the Union statements.  Since there will be thousands of records (my initial query has come up with 180,000 records) I dont believe using a cursor is a good idea.

    Again, thank you for your responses!

  • Mark,

    Keep in mind that the UNION statements are only there to populate the initial test data for the example.  That test data is then used in place where your static table would be referenced.  You will not need to duplicate that portion of the example.  The @table table will not exist in your final solution.  It will need to be replaced by the table or query where your data resides.  Feel free to post your whole query (or what you have of it so far) and we can help get you where you need to be. 

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

Viewing 3 posts - 16 through 17 (of 17 total)

You must be logged in to reply to this topic. Login to reply