Re: Row number in a select statement - 02-16-2005 , 04:59 AM
--SELECT * FROM jobs
Select job_desc, (Select Count(*) + 1 FROM jobs B
WHERE B.job_desc < A.job_desc) AS RecNo
FROM jobs A
ORDER By job_desc
Roji. P. Thomas
Net Asset Management
"Ashok" <akumar (AT) buildfolio (DOT) com> wrote
Row number in a select statement - 02-16-2005 , 04:59 AM
I am looking for a solution to get an incremental row number along my other
select arguments after joining more than one tables.
Thanks in advance.
Re: Row number in a select statement - 02-16-2005 , 05:42 AM
Why can't you do it client-side? That's probably much more efficient
than attempting it in SQL.
If you really must, the following is one example of a SQL-based method
(from Pubs). You've said that more than one table is involved but it's
hard to give a full answer for that more complex scenario without more
info - like the DDL for the tables involved and some sample data to
SELECT au_id, au_lname, au_fname,
WHERE au_id <= A.au_id) AS row_num
FROM Authors AS A
SQL Server MVP