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 )

10 comments:

Rama Udaya.K said...

Thanks Uri for the information!

Unknown said...

Thank Uri information!
2013 new nike nfl jerseys

Herry Johnson 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

Anonymous 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?

Unknown 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

ngocanhng said...

Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know. Nice! thank you so much! Thank you for sharing.
www.baixar-whatsapp-gratis.com.br

rmouniak said...

It's amazing blog, Thanks for sharing

Sql server DBA Online Course Bangalore

Sophie Grace said...

Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.Please visit my site picbear to know more information of your idols on instagram.

maxx said...

Thanks for sharing. I hope it will be helpful for too many people that are searching for this topic.
geometry dash
superfighters