Identity column on result set

  • Is there a way of creating an identity column, or similar, on a result set?

    I have the situation where I am joining, say, two table tables and I want a result set to have an identity column starting at 1 and incrementing for each row so if there are 20 rows in the result set I would have an identity column of 1 thorugh 20.

    I can do this by putting the results into a temporary table with an identity column and then selecting the rows from the temporary table but I was hoping that I could do this without a temporary table.

    Any suggestions or ideas?

    Jeremy

  • Hi Jeremy,

    quote:


    Is there a way of creating an identity column, or similar, on a result set?

    I have the situation where I am joining, say, two table tables and I want a result set to have an identity column starting at 1 and incrementing for each row so if there are 20 rows in the result set I would have an identity column of 1 thorugh 20.

    I can do this by putting the results into a temporary table with an identity column and then selecting the rows from the temporary table but I was hoping that I could do this without a temporary table.

    Any suggestions or ideas?


    maybe the ideas discussed here will help you

    http://www.sqlservercentral.com/forum/topic.asp?TOPIC_ID=14319&FORUM_ID=65&CAT_ID=1&Forum_Title=Performance+Tuning&Topic_Title=Numbering+the+ResultSet+%2D+Equivalent+of+Rownum

    hope the link isn't broken

    Cheers,

    Frank

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

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