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)
 listing the sort order for each record

Author  Topic 

indra7
Starting Member

5 Posts

Posted - 2006-05-22 : 14:48:23
ok,
I created a view of just one table that's sorted by an int field called TotalScore.
What I want to do is create a new field within the View (called 'Rank')
that will have the ranking of the sort order.

In other words, the field with highest value in 'TotalScore' should have a '1' in the 'Rank' field.

Any ideas on how to do this?
Thanks.

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-05-22 : 15:17:39
Give some sample data and expected results

Srinika
Go to Top of Page

indra7
Starting Member

5 Posts

Posted - 2006-05-22 : 17:48:13
Given this View:

CREATE VIEW [View_SSZ] AS
select Top 3 Color,TotPoints
from tblColor
order by TotPoints desc

where

Color,TotPoints
Blue, 36
Red, 33
Yellow, 29

I'd like to see:

Ranking,Color,TotPoints
1, Blue, 36
2, Red, 33
3, Yellow, 29

Thanks.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-05-22 : 17:58:57
Check out this article:
http://www.sqlteam.com/item.asp?ItemID=6398

Tara Kizer
aka tduggan
Go to Top of Page

indra7
Starting Member

5 Posts

Posted - 2006-05-22 : 19:54:49
It works beautifully.

Thanks.
Go to Top of Page
   

- Advertisement -