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)
 Maximum & Minimum values of variables

Author  Topic 

aclarke
Posting Yak Master

133 Posts

Posted - 2002-04-23 : 23:57:12
In other languages, doing something like max(100,200) would equal 200. Of course, in SQL, the max() variable does something else. Is there another way of getting the maximum or minimum of two values, other than resorting to if statements?

jbkayne
Posting Yak Master

100 Posts

Posted - 2002-04-24 : 00:17:01
How about the following?

select max(number)
from
(
select @var1 as number
union
select @var2
-- ... repeat for each variable
) as derived

Go to Top of Page

aclarke
Posting Yak Master

133 Posts

Posted - 2002-04-24 : 00:34:14
Hey. I thought about that, but it seemed it would be even more expensive and time consuming than a short series of if-thens. I only have 3 variables to sort this time; it was more of an academic curiosity than a driving, immediate need

Go to Top of Page
   

- Advertisement -