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)
 Return the Max Field

Author  Topic 

mlmeyer
Starting Member

26 Posts

Posted - 2005-06-07 : 09:43:11
I have a table that has the fields CustID, CountA, CountB. I would like to have a query just return the CustID and the highest value between CountA and CountB

so if this was the data
CustID......CountA.......CountB
123.............10...............15
234..............5................NULL

I would like it to return this output:
CustID.....MaxCount
123..............15
234...............5

In Oracle I could just use the 'Greatest' function but how do I do it in MS SQL?

X002548
Not Just a Number

15586 Posts

Posted - 2005-06-07 : 09:53:34
SELECT CustID, CASE WHEN ISNULL(CountA,CountB) > ISNull(CountB,CountA) Then CountA ELSE CountB END

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
Go to Top of Page
   

- Advertisement -