Questions tagged [iif]

The Immediate IF, which does not short-circuit, returns one of two values, depending on whether the boolean expression evaluates to true or false in SQL Server 2012, Visual Basic, and its variants.

Returns one of two values, depending on whether the Boolean expression evaluates to true or false in SQL Server 2012 and the variations of VB (VB6, VB.NET, VBA and VBScript)

Syntax


IIF ( boolean_expression, true_value, false_value )

Arguments


  • boolean_expression - A valid Boolean expression.If this argument is not a Boolean expression, then a syntax error is raised.
  • true_value - Value to return if boolean_expression evaluates to true.
  • false_value - Value to return if boolean_expression evaluates to false.

Return Types


Returns the data type with the highest precedence from the types in true_value and false_value (SQL Server). Visual Basic returns Object.

Remarks


For VB.NET, the newer If Operator is typically a better choice since it uses a short-circuit evaluation.

SQL Server/TSQLL

IIF is a shorthand way for writing a CASE expression. It evaluates the Boolean expression passed as the first argument, and then returns either of the other two arguments based on the result of the evaluation. That is, the true_value is returned if the Boolean expression is true, and the false_value is returned if the Boolean expression is false or unknown. true_value and false_value can be of any type. The same rules that apply to the CASE expression for Boolean expressions, null handling, and return types also apply to IIF. For more information, see CASE (Transact-SQL).

The fact that IIF is translated into CASE also has an impact on other aspects of the behavior of this function. Since CASE expressions can be nested only up to the level of 10, IIF statements can also be nested only up to the maximum level of 10. Also, IIF is remoted to other servers as a semantically equivalent CASE expression, with all the behaviors of a remoted CASE expression.

458 questions
5
votes
2 answers

How can I avoid running into false part in IIF?

I am trying to use the IIF in vb.net, here is my code Dim arr as new MyClass("ABC") MyAnotherMethod(IIf(arr.SelectedValue.Count < 1, Nothing, arr.SelectedValue(0).Value),"xxx","yyy","zzz") the above IIF will run into the true part, but after I run…
Steve Lam
  • 499
  • 1
  • 10
  • 27
4
votes
1 answer

using OR in IIF statement...RDLC

Please can you someone help me? My question is : How to use properly OR in IIF statement in RDLC report? Both Fields!A.Value and Fields!B.Value contains string or empty string. This code works fine: =Iif(Len(CStr(First(Fields!A.Value,…
marek
  • 43
  • 1
  • 1
  • 3
4
votes
4 answers

Lazy evaluation in SSRS

I'm using SSRS 2005 to produce a report, and one of the columns in my report is a simple mean calculation. I don't want to divide by zero, so for the textbox value I have put: …
Johnno Nolan
  • 29,228
  • 19
  • 111
  • 160
4
votes
2 answers

In an IIf function in Access, how do I assign null values?

I'm creating a calculated field (Field3) in a query in MS Access. In this example, Field2 contains both numeric and character values. I want Field3 to contain only numeric values from Field2 and to convert all character values to Null values so that…
LM6
  • 149
  • 3
  • 11
4
votes
1 answer

Dynamically change the font size of a single character in SSRS

Using SSRS in Visual Studio 2012 I currently have the following expression in the report header. =ReportItems!FirmName.Value This correctly pulls the Firm name such as Client1, Client2, Client3 etc... from the body of the report. However if…
Jay C
  • 842
  • 6
  • 17
  • 37
4
votes
1 answer

Import sales data into Quickbooks via .IIF files

I'm trying to import Sales into Quickbooks 2013 with an IIF file. Background: I'm developing an export engine for those IIF files for Quickbooks and now I'm trying to import sales datas into it. The message from Quickbooks is following: The Tax…
Ishmael
  • 41
  • 2
4
votes
1 answer

VB6 IIf advantage

Is there a performance advantage to using IIf over If? Other than simply less code... what is the difference between : If msInitialFloodSection <> Trim$(cboFloodSection.Text) Then mbFloodSectionChanged = True Else mbFloodSectionChanged =…
aserwin
  • 1,040
  • 2
  • 16
  • 34
4
votes
2 answers

Is it possible to use IIF within SUM in a C# DataColumn.Expression?

This is the expression I'm trying to evaluate: Sum(IIF(QUALITY<=9.0,1.0,0.0)) The problem is that string expr = "Sum(IIF(QUALITY<=9.0,1.0,0.0))"; dataTable.Compute(expr, "") throws an error saying Syntax error in aggregate argument: Expecting a…
jcsmnt0
  • 973
  • 10
  • 15
3
votes
1 answer

SumIIF Access Query

I am struggling to get the desired results i need using an Access query, and was wondering if what i was looking to do was actually achievable in one query, or whether i would need two queries and then export to Excel and interrogate the results…
Stuart
  • 45
  • 5
3
votes
1 answer

No such function: iif in SQLITE

community. I have a quite typical task in SQLITE. In case of X return Y, else Z. For such purpose I was using CASE statement "CASE WHEN X THEN Y ELSE Z END". However, I found IIF function in official…
3
votes
1 answer

How do I use the Lookup expression and the IIF expression in SSRS?

I have researched and not been able to find the answer to my question. My goal is to use the Lookup function in SSRS, which is currently performing as intended. However, I have null values that are not present which I would represented as '0'. It…
Thomas
  • 105
  • 1
  • 6
3
votes
2 answers

Error when combining IIF and 'Is Null'

I need to combine three columns representing address lines into one column, in order to compose the entire address here. All three columns can contain a NULL value. I thought the way to go about this is as follows: SELECT IIF((add1.AddressLine1 Is…
Cooz
  • 83
  • 1
  • 2
  • 10
3
votes
1 answer

SSRS - How to make IIF statement ignore invalid values

I am creating a table in SSRS with Business Intelligence 2008. I have a date, as a string, as one of the values used in the table. This value may have a string representing a date, OR it could also be blank. If it has a value, I want the value…
thnkwthprtls
  • 3,287
  • 11
  • 42
  • 63
3
votes
1 answer

Subquery in ISNULL,IIF,CASE statements

Subquery that is give as a parameter in ISNULL or IIF or CASE gets executed irrespective of the condition To explain what I mean, consider the below example. When I run the below query and look in the execution plan, I find that even if the variable…
mkr
  • 115
  • 1
  • 4
  • 12
3
votes
3 answers

report builder IIF() function with multiple TRUE value

I'm encountering an issue while develloping some report on RB. I have a tablix that where the columns are the hours of the day, and the rows are different products. I also have a parameter with 3 values (AM, PM, NIGHT). The point here is that if the…
Mask
  • 53
  • 1
  • 1
  • 9
1
2
3
30 31