Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Is Immediate If available in Sql Server ?

Posted on 1998-07-22
4
Medium Priority
?
1,286 Views
Last Modified: 2012-05-04
In Access there is a function called Immediate If ( IIF) which has the same functionality as ternary operation (?:) in C. I want to know whether there is a similar function in SQL Server.
0
Comment
Question by:Favourites
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Expert Comment

by:cymbolic
ID: 1089148
Nope, the closest you can come to conditional expression is in the use of the where and having clauses on your select statements, or use of IF/Else, Case, When/Then expressions.

Your best source for info if you have installed SQL Server client utilites is in SQL Server Books online, assuming you had enough space to install those as well.
0
 

Author Comment

by:Favourites
ID: 1089149
This is not what we are looking for.
We need to use the equivalent function of IIF(MS- Access2.0)
 in MS-Sql Statements.

Like for eg. DECODE function in oracle.

select decode(a.field1>30,a.field2,decode(a.field1<20,a.field3,a.field4))
from table1 a
where <condition>
0
 
LVL 2

Accepted Solution

by:
connex earned 100 total points
ID: 1089150
Well quite easy:
select case
    when a.field1>30 then a.field2
    when a.field <20 then a.field3
    else a.field4
from table1 wheree x=y

See also: Knowledgebase Article ID Q124243
          INF: Emulating iif() in Transact SQL

0
 

Author Comment

by:Favourites
ID: 1089151
good. I am able to solve the problem thru the answer u gave me. Thanks a lot.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question