all groups > sql server new users > february 2005 >
You're in the

sql server new users

group:

how to replace iif function is mssql



Re: how to replace iif function is mssql Sue Hoegemeier
2/27/2005 8:05:18 PM
sql server new users: You can usually use a case expression instead of the IIF.
Check SQL Server books online on the topic: CASE
The help topic has examples.

-Sue

On Mon, 28 Feb 2005 10:21:34 +0800, Vincent
[quoted text, click to view]
Re: how to replace iif function is mssql Walter Clayton
2/27/2005 10:05:34 PM
The closest you're going to come is the case or coalesce statement depending
on needs.

select cola
, case
when colb = 1
then 'one'
when colb = 2
and cola = 1
then 'twelve'
else 'huh?'
end as case1
, coalesce (colc, cold, cole, 'default') coalese1
from tab
;

CASE can be nested as in
CASE
when CASE
when
else
END
else
END

If there's no need to check for null you can code case as
CASE col
when 1 then 'one'
when 2 then 'two'
else 'huh?'
END

With CASE, the first condition that is true causes the value associate with
the 'then' clause to be returned. If no when condition is matched, then the
value specified by the else clause is returned. If no else clause is
specified then a null is returned.
COALESCE is a special version of the CASE statement. It simply returns the
first non-null value.


--
Walter Clayton
Any technology distinguishable from magic is insufficiently advanced.


[quoted text, click to view]
how to replace iif function is mssql Vincent
2/28/2005 10:21:34 AM
Hi,

Recently, i convert the database from access 2000 to mssql 2000. After
that, i find access sql function ' iif( , , ) ' can not be run on mssql
2000. So, my question is that any function can replace 'iif' in mssql
2000? Please give an example. Remark: If.. then..else can not be used in
Re: how to replace iif function is mssql Vincent
2/28/2005 11:40:24 AM
[quoted text, click to view]
AddThis Social Bookmark Button