Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a table which has some numeric columns and i have to find the greatest value from all column per row.

currently i am using this

SQL
SELECT
   CASE
       WHEN Col1 >= Col2 AND Col1 >= Col3 THEN Col1
       WHEN Col2 >= Col1 AND Col2 >= Col3 THEN Col2
       WHEN Col3 >= Col1 AND Col3 >= Col2 THEN Col3
       ELSE  Col1
   END AS MaxVal


but every time when one more column added i need to change all cases.

Is there any continent way to achieve this. Any thing like "greatest" in Oracle

I am using SQL Server 2000.

Thanks
--Pankaj
Posted
Updated 6-Mar-11 20:28pm
v3

1 solution

 
Share this answer
 
Comments
pankajupadhyay29 7-Mar-11 2:15am    
thanks.
pankajupadhyay29 7-Mar-11 2:27am    
this is fine for SQL Server 2005 and above any way for 2000

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900