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 2000 Forums
 Transact-SQL (2000)
 Hoew to Use IIF in the sql statement

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-10-07 : 07:44:42
Bakhtawar Singh Gill writes "select a.eqpid,b.prev_serialno,a.eqptype,Isnull(b.status,a.status),Isnull (b.changedt,a.RELEASEDT,b.changed),b.empid,b.templateid,b.templatecode,b.ishalf,b.prev_status,b.prev_changedt,a.ispromis from ESMS_EQUN a left outer join ESMS_ERUN b where (a.eqpid=b.eqpid) and (a.eqpid='CAT-01')

In the above statement i need to check some condition using iif function and it is giving problem. I oracle i can use
decode(b.changedt,null,a.RELEASEDT,b.changedt) but if i try to use in sql server like
iif(isnull(b.changedt),a.RELEASEDT,b.changedt) when i put this expersion in the sql statement do not work can please help to solve this problem.

Regards,
Gill"

nr
SQLTeam MVY

12543 Posts

Posted - 2002-10-07 : 07:47:41
look at the case statement which is the equivalent of iif.

case when b.changedt is null then a.RELEASEDT else b.changedt end

for this you could just

coalesce(b.changedt, a.RELEASEDT)

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -