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
 Transact-SQL (2000)
 RANK in SQL Server 2000

Author  Topic 

ranjith
Starting Member

2 Posts

Posted - 2006-09-22 : 07:04:35
Dear ALL,

Please suggest how to implement RANK feature in SQL Server 2000.
That should be Table independent.

Thanks in advance
Ranjith

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-22 : 07:28:53
What du you mean with independent?
Not even in SQL Server 2005 is RANK table independent. You must know what table you are working with, and which column, to get RANK.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

ranjith
Starting Member

2 Posts

Posted - 2006-09-22 : 07:38:23
Hi Peso,

I have written a function for the same but I have to give Table,Column to be Ranked and Top number of rows to be retrive.
I wants to have a generic function which can take parameters as Table,Column.
And this function needs to work in both SQL Server 2000 and SQL Server 2005

Please suggest.

Ranjith
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-09-22 : 08:20:37
quote:
Originally posted by ranjith

Hi Peso,

I have written a function for the same but I have to give Table,Column to be Ranked and Top number of rows to be retrive.
I wants to have a generic function which can take parameters as Table,Column.
And this function needs to work in both SQL Server 2000 and SQL Server 2005

Please suggest.

Ranjith




This is not how functions should work! In fact, it is not valid in SQL Server -- functions cannot use dynamic code. Table and column names should not be variable for a given function or stored procedure, they should be constants. Only your data itself should vary and be passed as parameters. If you have data stored in many tables that is all of the same type (i.e., if you have 1 table of Orders per customer) then they should all be in the same table.

It would be much better for you to step back and explain to us what you are trying to do and why you feel you need this. Hopefully it is not too late and we can help you fix your design to make things much, much easier and to follow best practices and to normalize your data.

- Jeff
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-09-22 : 09:36:16
Here's some stuff with dynamic predicates that provides a ranking...maybe it'll help

http://weblogs.sqlteam.com/brettk/archive/2004/05/05/1312.aspx



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page
   

- Advertisement -