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)
 IF(expression, thenValue, elseValue)

Author  Topic 

majkinetor
Yak Posting Veteran

55 Posts

Posted - 2008-09-09 : 06:21:22
Hello there. I see that mysql has this kind of thing

IF(winter>500, "Sells", "Slow")


I am aware of CASE command but i would like to have above code in SqlServer. Is there any way that it can be defined as function.

Can you suggest me how this could be done ?

I tried with creating function IFF( bit, varchar, varchar ) but then you cant put expressions as function arguments...

Let me put it in example. Lets say I want to have 1 returned if count(*) > 1 otherwise 0. I could put it like:

SELECT IFF(Count(*) > 0, 1, 0) FROM table


Thank you

www.r-moth.com          http://r-moth.deviantart.com

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-09-09 : 06:25:32
Select Case when count(*) > 0 Then 1 else 0 end as ColCount from table
Go to Top of Page

majkinetor
Yak Posting Veteran

55 Posts

Posted - 2008-09-09 : 09:01:29
quote:
I am aware of CASE command but i would like to have above code in SqlServer


www.r-moth.com          http://r-moth.deviantart.com
Go to Top of Page
   

- Advertisement -