Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to: Adding a query autonumbering for the corresponding records

Status
Not open for further replies.

GreekPatriot

Technical User
Nov 16, 2004
91
CY
is there a way to add a query hierarchy level for each record available in the database query?? (1, 2, 3, 4, ..)

I tried count() but does not work. What am I doing wrong??
 
Tyere may be others who might help but, like me, don't know what you mean by " query hierarchy level ".
Can you provide an example.
 
If you are talking about enumerating each record in the query's result set, I don't think so.

[shadeshappy] Cruising the Information Superhighway
(your mileage may vary)
 
Provided you have a sort key for numbering:
SELECT A.*, (SELECT Count(*) FROM yourTable B WHERE B.SortKey<=A.SortKey) AS Rank
FROM yourTable A
ORDER BY A.SortKey

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Just keep in mind that this will be horrible on performance as it has to exexute a subquery on each row that the main query returns. It your talking about a table with 30 or 40 records...not a problem. If your talking a table with 10,000 records...watch out!

[shadeshappy] Cruising the Information Superhighway
(your mileage may vary)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top