Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sybase Equivalent to IIF?

1,721 views
Skip to first unread message

da...@carlson.com

unread,
Jan 26, 1999, 3:00:00 AM1/26/99
to
Does anyone know if there is a function out there(so I don't have to
reinvent the wheel). Sybase Equivalent for IIF


I want to do something like this:


Select Name, IIF(Sex = 'M', 'Male', 'Female') From dbfile

Paul Robles

unread,
Jan 26, 1999, 3:00:00 AM1/26/99
to
Try somthing like this:

select Name, if Sex='M' then 'Male' else 'Female' endif as "Sex" from
dbfile

Paul Robles
pro...@nettally.com

da...@carlson.com wrote in message ...

Da...@carlson.com

unread,
Jan 26, 1999, 3:00:00 AM1/26/99
to
In article <araHiOVS#GA....@forums.powersoft.com>
"Paul Robles" <pro...@nettally.com> wrote:

> Try somthing like this:
>
> select Name, if Sex='M' then 'Male' else 'Female' endif as "Sex" from
> dbfile
>
> Paul Robles
> pro...@nettally.com
>

Sheesh. I would of NEVER of thought of using a IF/ENDIF in a Query like this. Boy the
things you learn.

I just tried it out on a database I have here and works wonders. Thanks!


David Leckenby

unread,
Feb 2, 1999, 3:00:00 AM2/2/99
to
On Tue, 26 Jan 1999 15:28:24 -0500, Da...@carlson.com wrote:

>Sheesh. I would of NEVER of thought of using a IF/ENDIF in a Query like this. Boy the
>things you learn.
>
>I just tried it out on a database I have here and works wonders. Thanks!

You might also be interested in the 'Case When' statement as the
If/EndIf limits you to only 2 options (as does IIF).

Eg (straight from the help):
SELECT id,
( CASE name
WHEN 'Tee Shirt' then 'Shirt'
WHEN 'Sweatshirt' then 'Shirt'
WHEN 'Baseball Cap' then 'Hat'
ELSE 'Unknown'
END ) as Type
FROM "DBA".Product

Or even better:
SELECT id, name,
( CASE
WHEN name='Tee Shirt' then 'Sale'
WHEN quantity >= 50 then 'Big Sale'
ELSE 'Regular price'
END ) as Type
FROM "DBA".Product


>


0 new messages