[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

IIF function in sql server

Posted on 2004-08-18
7
Medium Priority
?
2,547 Views
Last Modified: 2008-11-17
Hi Freinds,
Please help me with the IIF function in sql
Getting syntax error for following line at = sign

iif (cast(rcv_stats_shelter_plus_chk_c as int)=1, 1, 0)

The query is returning as syntax error near =

Really frustrated with this. Please help

Thanks,
Rup
0
Comment
Question by:rk75
[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
7 Comments
 
LVL 17

Accepted Solution

by:
BillAn1 earned 80 total points
ID: 11834764
you may want a case statement :

case cast(rcv_stats_shelter_plus_chk_c as int)
when 1 then 1
else 0
end
0
 
LVL 10

Expert Comment

by:Jay Toops
ID: 11835461
its returning an error because IIF is not supported with sql server ..

so you have to use the case statement AND...
you can INLINE this case statement with regular sql
you might want to add " AS FIELDNAME" IMMediately after the END

example
case cast(rcv_stats_shelter_plus_chk_c as int)
when 1 then 1
else 0
end as MYFIELDNAME
0
 
LVL 3

Expert Comment

by:eekj
ID: 11837947
Write your own immediate if function:

CREATE  FUNCTION iif
    (@Expr AS int, @TruePart AS int, FalsePart AS int)

RETURNS int

BEGIN
    if @Expr = 1 then   --some databases such as mysql evaluate an expression to 0=false 1=true
        return @TruePart
    else
        return @FalsePart
END
0
 

Author Comment

by:rk75
ID: 11852542
Thnaks friends,
I used case.... when.... then....else....end
in the place of iif
And it worked.

Thanks for your time and help
RK
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 11852578
>>Thanks for your time and help<<
Than this is the point where you close the question by awarding points.  See here for more info:
How do I accept a comment?
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/help.jsp#hi68
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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

656 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