Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2002
    Posts
    33

    Unanswered: generate a sequential number

    Hi,
    I'm trying to generate a sequential number as part of a query I have.
    I'm sorting the query using one of the items and need to generate a sequential number from 1 to N for the number of items in the selection.
    I thought it sounds easy but could not figure this out…Help please



    Thanks
    Motty

  2. #2
    Join Date
    Oct 2002
    Posts
    369

    Re: generate a sequential number

    Hi, I'm trying to generate a sequential number as part of a query I have. I'm sorting the query using one of the items and need to generate a sequential number from 1 to N for the number of items in the selection. I thought it sounds easy but could not figure this out…
    Q1 Help please
    Thanks Motty
    A1 As presented, this is a very general requirement however one approach to the issue (which may or may not be suitable depending on the detailed requirements), may be to insert the result set into a newly created #Temp table with an identity column seeded at 1.

  3. #3
    Join Date
    Dec 2002
    Location
    Czech Republic
    Posts
    249
    Same functionality with identity function and select into

    select OrderId=identity(int,1,1),*
    into #Table
    from YourTable
    order by ColumnX

Posting Permissions

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