Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 rownumber on the fly?

Author  Topic 

Cyclonik
Posting Yak Master

114 Posts

Posted - 2006-04-04 : 13:06:17
How would I create an artificial row number in a select statement?

example: select @rownum=@rownum+1, column from table

Thanks,

Christian

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-04-04 : 13:50:33
[code]USE Pubs
SELECT COUNT(e1.emp_id) as [record #], e1.emp_id , e1.fname, e1.lname
FROM employee AS e1
INNER JOIN employee AS e2 ON e1.emp_id >= e2.emp_id
group by e1.emp_id , e1.fname , e1.lname
order by e1.emp_id[/code]

Srinika
Go to Top of Page

Cyclonik
Posting Yak Master

114 Posts

Posted - 2006-04-04 : 14:00:20
THanks. This solution seems rather slow. Any more high performance way to accomplish this?
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-04-04 : 14:05:37
If this is SQL 2005, its said to be direct.
In SQL 2000, check the following :
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=60323

(Specially MVJ's method)


Srinika
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-05 : 01:49:34
Where do you want to show the data?
Use front end application to number the result. Just send data to client application

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -