Solved

Is Immediate If available in Sql Server ?

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

635 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