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)
 IIF Function in SQL 2005?

Author  Topic 

sgrahman
Starting Member

10 Posts

Posted - 2007-07-26 : 12:57:36
I was able to do the following in MS Access using IIF function. T-SQL does not support IIF so I am stuck. Please help.

I have field1, field2 and field3

I want to write a IF and Else statement like below in T-SQL or is there anyway to write this in SQL 2005:

IF (field1=field2 and field2=field3 and field1=field3) then 1 else 0

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-07-26 : 13:00:38
CASE WHEN (field1=field2 and field2=field3 and field1=field3) then 1 else 0 END

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-07-26 : 13:49:28
You might find this useful:

http://weblogs.sqlteam.com/jeffs/archive/2007/03/30/Quick-Access-JET-SQL-to-T-SQL-Cheatsheet.aspx

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

sgrahman
Starting Member

10 Posts

Posted - 2007-07-26 : 14:23:21
I used case statement by Dinakar and it worked fine. Thanks.
Also thanks to JSMith8858 for your post.
Go to Top of Page
   

- Advertisement -