Simple question for quick answer

  • Hello,

    I have data like:

    Gold 111

    Silver 222

    Bronze 333

    Now I need to return result like:

    1 Gold 111

    2 Silver 222

    3 Bronze 333

    What's the simple approach to this? Thanks.

  • Use ROW_NUMBER().

    John Rowan

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

  • I was just going to suggest RowNumber as well

    CREATE TABLE #tmpdta (Mat VARCHAR(25), num INT)

    INSERT INTO #tmpdta (

    Mat,

    num

    ) VALUES

    ('Gold',111 ),

    ('Silver',222 ),

    ('Bronze',333 )

    SELECT ROW_NUMBER() OVER(ORDER BY NUM DESC ) AS RowNumber,*

    FROM #tmpdta

    ** My Insert into used a SS2k8 ability

  • But then again, if you wanted really simple, you could just do:

    ...

    select right(field2,1),field1,field2

    from x

    but I'm guessing that those numbers are made up 😛

  • Thanks for the answer.

Viewing 5 posts - 1 through 4 (of 4 total)

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