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 2005 Forums
 Transact-SQL (2005)
 Taking a Minimum

Author  Topic 

DavisJ44
Starting Member

9 Posts

Posted - 2009-02-19 : 10:28:08
I'm new to SQL Server, but very familiar with DB2 and Oracle. In DB2 you can take the minimum of two values by the following:

MIN(a,b)

However, when I use this technique in SQL Server it says MIN only takes one argument and it tries to take the minimum of a column. What if I have two values in a single row and want to return the minimum of the two?

Thanks in advance

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-02-19 : 10:29:37
theres nothing in sql server for this. You'll have to use case statement.
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-02-19 : 10:30:44
Something like,

case when a<b then a else ... end 
Go to Top of Page

DavisJ44
Starting Member

9 Posts

Posted - 2009-02-19 : 10:43:04
Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-19 : 11:24:51
or

SELECT MIN(Val)
FROM
(
SELECT a AS Val FROM Table
UNION ALL
SELECT b FROM Table
)t
Go to Top of Page
   

- Advertisement -