Showing posts with label sybase. Show all posts
Showing posts with label sybase. Show all posts

Wednesday, March 21, 2012

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,
GeoffOriginally 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|||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 #tempsql