Wednesday, March 28, 2012

query

hi,

i want to achive the IIF functionality.

example

select

iff(employee.empid is not null,'sdfsdf',iif(employee.deptid is not null,'dssdf','sdfsd')) as 'sdsd'

from employee

how to solve this.

thank you

Hi,

did not understand what you wants to achieve! You may use if and try...catch block or you may use case statements too.

Refer CASE and try...catch for more in BOL.

Regards

Heamntgiri S. Goswami

|||

IFF is not a part of TSQL syntax as far as i know...though this function is provided in sql server 2005 reporting services (thats the place i used it)...

finctionality of IFF is

IFF(mycondition , ValueWhenMyConditionTrue, ValueWhenMyConditionFalse)

IFF can also be nested...so for ValueWhenMyConditionFalse u can write another IFF...as is done in ur case...i hope u'll be able to 'decode' ur actual code now...

|||You can use an IF in SQL.

Its normally shown as

IF EXISTS (SELECT * FROM Orders WHERE OrderNo = @.OrderNo) THEN|||Also you use NotIsNull(Expr1, Expr2)
|||

IIF is not available in T-SQL.

But you can use Case When,

Case When employee.empid is NOT NULL Then 'sdfsdf' Else (Case When employee.deptid is not null Then 'dssdf' Else 'sdfsd' End) End

No comments:

Post a Comment