Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2004
    Posts
    2

    Unanswered: Sequence Numbers in Sql Server

    Is is possible to Generate sequence numbers in a Query result in an SQL select Statement

    like

    Select sno,employee_name from empmaster

    sno being a number with auto increments(this Field will not be in a Table).

    I do not want to use Identity .....

    This is Just to Provide a Serial Number to the Query Output...

    thus the Out put should be something like

    sno employeename
    --- ------------------
    1 abc
    2 jhjk
    3 kljl

  2. #2
    Join Date
    Aug 2002
    Location
    Scotland
    Posts
    1,578

  3. #3
    Join Date
    Feb 2004
    Posts
    2

    Gr8

    Thanks a Ton ... This is wat i Wanted...

  4. #4
    Join Date
    Oct 2011
    Posts
    2

    Arrow Dynamically number rows in a SELECT Transact-SQL statement

    Answer:
    Just try with this Query:

    Select sno=count(*),a.employee_name
    from empmaster a,empmaster b
    where a.employee_name >= b.employee_name
    group by a.employee_name
    order by sno


    ----Output-----------

    sno employeename
    --- ------------------
    1 abc
    2 jhjk
    3 kljl[/QUOTE]


    ---------
    Roni Shikder
    blog-site: ShikderS
    Last edited by Pat Phelan; 10-20-11 at 00:30.

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by ronishikder View Post
    Answer:
    Just try with this Query:
    there are three issues here

    first, your solution was already given (did you even bother to check the link in post #2?)

    second, your solution is grossly inefficient

    third, i doubt very much that the original poster is still waiting for an answer after over seven years, especially in view of his reply in post #3

    but thanks for trying
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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