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 2008 Forums
 Transact-SQL (2008)
 Picking 1 of 2 numbers

Author  Topic 

igator210
Starting Member

5 Posts

Posted - 2012-05-14 : 11:28:21
I have an Excel formula....

if(A<B,A,B)

For TSQL, would that be written...

CASE WHEN (A<B) THEN (A) ELSE (B) END


Nate

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-05-14 : 11:35:45
Yes. The parentheses are not strictly required either, unless you have compound conditions that mix AND and OR.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-14 : 23:16:20
sql 2012 onwards you've IIF too

IIF(A>b,A,B) AS yourcol

http://msdn.microsoft.com/en-us/library/hh213574.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -