Returning row number of result set next to each item in result set

  • Hi.

    I have a result set of data (select Surname, forename, from tblAddress).

    I also want next to each name in the list the row number eg

    1

  • In Sql Server 2005, you'll be able to use the ROW_NUMBER() / OVER function to generate this.

    In prior versions, I don't know any other way than to pre-select into a temp table or table variable with an Identity column

    Declare @RownumData Table (

      RowNum int Identity,

      Surname varchar(100),

      Forename varchar(100)

    )

    Insert Into @RownumData

      (Surname, Forename)

    Select Surname, forename

    From tblAddress

    Order By Surname, Forename

    -- View results

    Select * From @RownumData

  • Definetly That's one way for more go here 

    HTH


    * Noel

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

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