Row sequence number

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • evandroc

    Row sequence number

    Hello all,


    I´m currently using a SQL Serve 2K. Would like to do a select
    which returns the row number - this should not be physically stored in
    the database. So for example, I would like to do a query against the
    CUSTOMER table and receive:

    * rowID || name
    1 Evander
    2 Ron
    3 Scoth
    4 Jane

    I don´t want to store the ID, because if I change the order by
    clause, the sequence may modifiy, and, for another example, having the
    same set of data, I would receive:

    * rowID || name
    1 Scoth
    2 Ron
    3 Jane
    4 Evander

    could someone help me ?

    best regards,
    Evandro

  • --CELKO--

    #2
    Re: Row sequence number

    Let's get back to the basics of an RDBMS. Rows are not records; fields
    are not columns; tables are not files; there is no sequential access or
    ordering in an RDBMS, so "first", "next" and "last" are totally
    meaningless. If you want an ordering, then you need to have a column
    that defines that ordering. You must use an ORDER BY clause on a
    cursor or in an OVER() clause.
    [color=blue][color=green]
    >> could someone help me ? <<[/color][/color]

    You can help yourself by doing about one week's worth of reading on
    RDBMS. You are making a fool of yourself by not knowing the basics.

    Comment

    • Sergey

      #3
      Re: Row sequence number

      SQL 2000 does not have this pseudo-column. It is introduced in 2005.
      The only way I know how to way around it is to dump your query into
      temp. table that has anextra column (let's call it rowID ) which is an
      auto-increment.

      Comment

      • Erland Sommarskog

        #4
        Re: Row sequence number

        Sergey (afanas01@gmail .com) writes:[color=blue]
        > SQL 2000 does not have this pseudo-column. It is introduced in 2005.
        > The only way I know how to way around it is to dump your query into
        > temp. table that has anextra column (let's call it rowID ) which is an
        > auto-increment.[/color]

        Neither does SQL 2005 have any pseudo-column. row_number() is a function,
        and you can set it up so that it restarts on some defined partition.



        --
        Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

        Books Online for SQL Server 2005 at

        Books Online for SQL Server 2000 at

        Comment

        Working...