Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2004
    Posts
    30

    Unanswered: Select Statement

    Is there any way i can get the row nos printed along with the records selected
    For eg: Select SlNo, Names from Mytable
    here Slno is not a Table column, Names is a table column in Mytable
    The result recordset has to be like
    Slno Names
    1 ABC
    2 AAA
    3 BBBB

    where 1,2,3 should be autogenerated and can be used in a recordset as a column (Is there any function for this)

  2. #2
    Join Date
    Feb 2004
    Posts
    492
    There's no default sql function that does this for you. However, the most common way to do this is to insert the rows into a temporary table that has an identity column. Then select the lot from the temp. table.

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Assuming that Names is a primary key, or at least a unique constraint:

    Select Count(RowTable.Names) as RowNumber, Mytable.Names
    from Mytable
    inner join Mytable RowTable on Mytable.Names >= RowTable.Names

    I have to ask why you want to do this. It is seldom necessary.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •