Wednesday, October 31, 2012

SQL Server 2012 IIF function may replace CASE expression?


Hi
Did you install already SQL Server 2012? Well, see a new T-SQL function named IIF you can use sometimes instead of CASE expression.
http://msdn.microsoft.com/en-us/library/hh213574.aspx


CREATE TABLE #t (id INT)

INSERT INTO #t VALUES (1),(2),(3)

DECLARE @a int = 3;
DECLARE @b int = 2;

SELECT * FROM #t WHERE id= IIF ( @a > @b, @a, @b )

Returns Id=3.

You can even using nested IIF commands.
SELECT * FROM #t WHERE id= IIF ( @a > @b, IIF(@a>0,@b,0), @b )

6 comments:

Rama Udaya.K said...

Thanks Uri for the information!

Norred Michal said...

Thank Uri information!
2013 new nike nfl jerseys

Herry jonson said...

ARINET DBA Services is a Chicago, IL based organization established in 2013. Uniting more than 100+ years of combined involvement in giving quality Oracle database Support administrations to American organizations, we've given the diverse options about remote dba experts, remote dba organizations, remote dba reinforce, remote database, oracle remote, dba remote, database association, prophet dba reinforce, Oracle sponsorship and Oracle Consultants.

Drag Racer V3 said...

Many thanks for sharing friv4schoolonline.net

Thu LĂȘ said...

I was very impressed by this post, this site has always been pleasant news. Thank you very much for such an interesting post. Keep working, great job! In my free time, I like play game: superfighters2.net. What about you?

Dr Driving said...

Thank you for your post, I look for such article along time, today i find it finally. this post give me lots of advise it is very useful for me
run3unblockedgame.com