Solved

Is Immediate If available in Sql Server ?

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now