Questions tagged [iif-function]

IIf is a language function to perform an immediate or inline conditional assignment.

IIf is an abbreviation variously for Inline If or Immediate If and is available in many programming and script languages, IIf is implemented as a Function which means it returns a value. In code, these typically take the form:

result = IIf(condition, TruePart, FalsePart)

The value of result afterwards depends on the evaluation of condition.

A multi-line If block could perform the same action but would be an If Statement. The statement form could include any number of other actions such as invoke other methods. On the other hand, IIf simply results in a conditional assignment and cannot invoke other code.

Some languages also support a 'conditional operator', sometimes called a ternary operator, which works similar to IIf, but may offer other benefits.

94 questions
102
votes
9 answers

Performance difference between IIf() and If

In Visual Basic, is there a performance difference when using the IIf function instead of the If statement?
Bryan Roth
  • 10,479
  • 15
  • 47
  • 56
85
votes
7 answers

Iif equivalent in C#

Is there an IIf equivalent in C#? Or similar shortcut?
Saif Khan
  • 18,402
  • 29
  • 102
  • 147
25
votes
1 answer

SSRS Conditional Formatting Switch or IIF

I currently have the following 2008 SSRS Report and I want to conditionally format background of the columns based on some logic. I have three columns and two of which I would like to change the background color. Columns "Current Risk Level",…
20
votes
3 answers

Does the iif function compute both paths in SSRS or is it short-circuited?

I am trying to evaluate a Price per Kilo ($/Kg) based on sales of a product. This works fine if the product was acutally sold during the period specified. However if the product is not sold the Kg (the denominator) ends up being 0 (zero) and an…
Nathan Fisher
  • 7,961
  • 3
  • 47
  • 68
19
votes
1 answer

python: iif or (x ? a : b)

Possible Duplicate: Python Ternary Operator If Python would support the (x ? a : b) syntax from C/C++, I would write: print paid ? ("paid: " + str(paid) + " €") : "not paid" I really don't want to have an if-check and two independent prints here…
Albert
  • 65,406
  • 61
  • 242
  • 386
16
votes
7 answers

SSRS Formula or expression to change NaN to 0

I am using the following expression to work out a percentage: =Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name") Days.Value is showing as 0 however in a few of my results instead of reading 0% in my percentage column it is actually…
JsonStatham
  • 9,770
  • 27
  • 100
  • 181
13
votes
1 answer

Conditional Action in SSRS

I want my textbox to have an action ONLY if the condition is true, otherwise no action. This is what I have as my current action expression for going to another report: =IIf(Fields!MyTextbox.Value = "0", "Report2","") This does not produce my…
Jesse
  • 2,043
  • 9
  • 28
  • 45
11
votes
4 answers

Java Equivalent to iif function

the question is simple, there is a functional equivalent of the famous iif in java? For example: IIf (vData = "S", True, False) Thanks in advance.
seba123neo
  • 4,688
  • 10
  • 35
  • 53
11
votes
2 answers

If, IIf() and If()

I recently asked a question about IIf vs. If and found out that there is another function in VB called If which basically does the same thing as IIf but is a short-circuit. Does this If function perform better than the IIf function? Does the If…
Bryan Roth
  • 10,479
  • 15
  • 47
  • 56
8
votes
4 answers

How to check multiple conditions in rdlc expression

I have worked on only possible 2 in rdlc Expression values as like =iif((Fields!Gender.Value="1"),"Male","Female") Here I can work with only 2 possibilities. But if I want to check 3 or more conditions than how can I?
Sonam Mohite
  • 885
  • 4
  • 19
  • 51
6
votes
1 answer

"Conversion from type 'DBNull' to type 'Boolean' is not valid", after checking that it's not DBNull

In my ASP.Net Web-Application, I'm getting this error: Conversion from type 'DBNull' to type 'Boolean' is not valid. From this function: Namespace atc Public Class Nil '... Public Shared Function Bool(ByVal Item As Object) As…
Drew Chapin
  • 7,779
  • 5
  • 58
  • 84
5
votes
4 answers

Crystal Reports formula: IsNull + Iif

There are hints of the answer to this question here and there on this site, but I'm asking a slightly different question. Where does Crystal Reports document that this syntax does not work? Trim({PatientProfile.First}) + " " + Trim(Iif( …
SarekOfVulcan
  • 1,348
  • 4
  • 16
  • 35
5
votes
1 answer

IIF statement with a Yes/No Field

I have a question about using an IIF statement with a Yes/No field. In my case, I am trying to get the statement do one thing if the Yes/No field=Yes and another if it is "No." I realize Access stores the Yes/No field as -1,0 and have attempted to…
user3185924
  • 51
  • 1
  • 2
  • 6
3
votes
1 answer

SSRS SWITCH Syntax not working

I have a columns in my dataset that will be returning several different values. In an attempt to to use grouping in the report I am trying to clean up the data. After reading several posts I found this post that seemed to be very close to what I…
Perry
  • 1,277
  • 2
  • 17
  • 39
3
votes
2 answers

Problem evaluating NULL in an IIF statement (Access)

Item in the recordset rstImportData("Flat Size") is = Null With that, given the following statement: IIF(IsNull(rstImportData("Flat Size")), Null, cstr(rstImportData("Flat Size"))) Result: Throws error 94: Invalid use of Null If I change the…
Mohgeroth
  • 1,617
  • 4
  • 32
  • 47
1
2 3 4 5 6 7