Solved

Is Immediate If available in Sql Server ?

Posted on 1998-07-22
4
1,271 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
  • 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 50 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

713 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