Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    3

    Red face Unanswered: Line Number in Transact SQL

    Hi,

    How do you generate line numbers in Transact SQL?

    Example:

    In Sybase, I could use this...
    select number(*), customer_name from customer_table

    number(*) customer_name
    ----------------------------------------------------
    1 Customer Name 1
    2 Customer Name 2
    3 Customer Name 3


    Thanks,
    Geoff

  2. #2
    Join Date
    Jan 2003
    Location
    India
    Posts
    523

    Re: Line Number in Transact SQL

    Originally posted by geoff_sy
    Hi,

    How do you generate line numbers in Transact SQL?

    Example:

    In Sybase, I could use this...
    select number(*), customer_name from customer_table

    number(*) customer_name
    ----------------------------------------------------
    1 Customer Name 1
    2 Customer Name 2
    3 Customer Name 3


    Thanks,
    Geoff

    select number=identity(int,1,1), fak.* into #temp

    from (select top 100 percent customer_name from customer_table order by 1) fak

    select * from #temp order by 1

    drop table #temp
    Last edited by harshal_in; 02-16-04 at 05:18.

  3. #3
    Join Date
    Feb 2004
    Posts
    6

    Re: Line Number in Transact SQL

    I don't understant why you suggested a nested query it could more simple I think eg:

    select number=identity(int,1,1), customer_name into #temp
    from customer_table order by 1 -- (or any other column)


    Originally posted by harshal_in
    select number=identity(int,1,1), fak.* into #temp

    from (select top 100 percent customer_name from customer_table order by 1) fak

    select * from #temp order by 1

    drop table #temp

Posting Permissions

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