Hi
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.
Ashokuse pubs
GO
--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
https://www.netassetmanagement.com
"Ashok" <akumar@.buildfolio.com> wrote in message
news:uweREUBFFHA.2156@.TK2MSFTNGP10.phx.gbl...
> Hi
> 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.
> Ashok
>
>|||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
work with.
SELECT au_id, au_lname, au_fname,
(SELECT COUNT(*)
FROM Authors
WHERE au_id <= A.au_id) AS row_num
FROM Authors AS A
David Portas
SQL Server MVP
--
No comments:
Post a Comment