5 Replies - 353 Views - Last Post: 21 November 2011 - 03:38 PM Rate Topic: -----

#1 Criel  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 128
  • Joined: 11-March 11

IIF statement

Posted 21 November 2011 - 03:14 PM

Hello,

I recently started a new job in IT and have been looking at their code for the past week or two and noticed they use the IIF function alot. I've never seen it and wasn't taught it in school - are there any benefits to using this rather than an if/else rather than to save lines of code?

edit: IIF function*********

This post has been edited by Criel: 21 November 2011 - 03:16 PM

Is This A Good Question/Topic? 0
  • +

Replies To: IIF statement

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9197
  • View blog
  • Posts: 34,551
  • Joined: 12-June 08

Re: IIF statement

Posted 21 November 2011 - 03:19 PM

Depends where you are using it at... say in reporting services that's their short hand for doing an if-else statement in a cell. Same with dataset's columns as well.

No particular advantage - just different syntax.
Was This Post Helpful? 1
  • +
  • -

#3 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: IIF statement

Posted 21 November 2011 - 03:22 PM

I would guess it would depend on what they are trying to achieve with there code. It's hard to say what is better without knowing what the code is doing i would suggest reading up on IF statement then go and read their code and come to you own conclusion.

Whoops modi beat me to it

This post has been edited by m_wylie85: 21 November 2011 - 03:23 PM

Was This Post Helpful? 1
  • +
  • -

#4 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: IIF statement

Posted 21 November 2011 - 03:23 PM

Another advantage of IIF() is that it improves code readability when used appropriately.
Was This Post Helpful? 1
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9197
  • View blog
  • Posts: 34,551
  • Joined: 12-June 08

Re: IIF statement

Posted 21 November 2011 - 03:26 PM

Haha.. or destroys it with some overly complex data column's "Expression". Ugh.. Nest about twelve (or more) of those together and you'll know pain.
Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,464
  • Joined: 29-May 08

Re: IIF statement

Posted 21 November 2011 - 03:38 PM

IIF is a throwback to vb6, thus has to maintain compatibly.

It has the side-effect (read as problem) that it evaluates both side of the statement before deciding which to use.

If has single line overload, evaluates only the require statement.

Dim x=If( condition, onTrue, onFalse)

This post has been edited by AdamSpeight2008: 21 November 2011 - 03:40 PM

Was This Post Helpful? 3
  • +
  • -

Page 1 of 1