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)
 Select Highest Valued Field

Author  Topic 

davidpardoe
Constraint Violating Yak Guru

324 Posts

Posted - 2001-09-05 : 07:32:09
Does anyone have any design suggestions for the following situation...

I have a table with say 5 fields plus an URN (ultimately I would like this to work with any number of fields). I wish to be able to select the field with the highest value for each row. For example I have the table:-

URN Col1 Col2 Col3 Col4 Col5
============================
1 10 11 12 13 14
2 11 10 14 12 13
3 14 13 12 10 11

My result set should be something like:-

URN MaxCol
==========
1 Col5
2 Col3
3 Col1

In addtion I would like to be able to specify which columns should be compared. For the above data I may want to exclude Col1 from my comparison, resulting in:-

URN MaxCol
==========
1 Col5
2 Col3
3 Col2

Any thoughts.

Might it be easier to do if I create a new table with 1 row per "Col" value - ie. in the above case I would have 5 lines per URN?

Any help would be invaluable.

============
The Dabbler!
   

- Advertisement -