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
2
votes
1 answer

ReportViewer IIf expression in text box returns #ERROR

I'm using ReportViewer for work and I'm trying to get an IIf expression to work with a few text boxes that are using FormatCurrency(). The reason I needed an IIf statement in the first place was because occasionally on this report, there will be…
Sam
  • 317
  • 1
  • 4
  • 13
2
votes
2 answers

Incorrect syntax near '<'

I have a task to get some code which is working correctly on SQL Server 2012 to work on SQL Server 2008 R2 as well. I got this error: Additional information: Incorrect syntax near '<' When I try to run my code I found out that something is wrong…
Stefan
  • 1,431
  • 2
  • 17
  • 33
2
votes
1 answer

IIF Function from SQL to HSQLDB

I have the following SQL statement in MS Access - WITH qryAwayMatches AS (SELECT MATCHTEAM.FOOTBALLMATCHID, MATCHTEAM.TEAMID, MATCHTEAM.GAMETYPE, MATCHPROTOCOL.MATCHTEAMID, MATCHPROTOCOL.GOALNUMBER, MATCHPROTOCOL.YELLOWCARDNUMBER,…
vs97
  • 5,765
  • 3
  • 28
  • 41
2
votes
2 answers

Sum IIF with multiple values in SSRS

I am having an issue with my expression. I am trying to write: if it finds these specific codes in the Dataset column, Sum them and return the amount. However, I am receiving #ERROR. Any help with this expression is really…
Geo
  • 336
  • 1
  • 6
  • 20
2
votes
2 answers

Iif function in SQL Server Report Builder 2012 3.0

I'm trying to make an automatic invoice but the final part gets me stuck. If a client is not from the same country as the supplier then he shouldn't pay VAT. To get this in my invoice I'm trying to insert an expression but it gives the following…
2
votes
3 answers

Syntax error using IIf

This is a simple question I hope. I learned about IIf today and want to implement it in some cases to save a few lines. IIF(isnumeric(inputs), resume next, call notnum) This is in red meaning there is a syntax error, how fix this? I have scanned…
user4974730
2
votes
2 answers

Visual Studio : ASPX : corrupted 'IIf' syntax : strange error

The following declaration in my ASPX file contains an ERROR within the IIf() arguments...
The…
John D
  • 517
  • 7
  • 22
2
votes
1 answer

Error on iif for color expression

I have this statement in my SSRS report. =iif( ((Fields!lngCount2.Value-Fields!lngCount.Value)/Fields!lngCount.Value) > 0 and Fields!strSegmentName.Value ="Struggler" or Fields!strSegmentName = "Winback" or…
Jeff
  • 21
  • 1
  • 2
2
votes
1 answer

If Condition of VB.NET (IIf) is not equal by C# (?:)

The IIf function in VB.NET : IIf(condition As Boolean, TruePart As Object, FalsePart As Object) As Object exactly is not equal by C# conditional operator (?:) : condition ? first_expression : second_expression; When I convert some codes from c# to…
Behzad
  • 3,502
  • 4
  • 36
  • 63
2
votes
2 answers

#Error in IIF formula

I am using report builder and I have created an IIF statement on a calculated field I have created (called Tolerance) The field of "Tolerance" is returning a difference in time between two other fields in the format of 00:00:00. My IIF statement is…
2
votes
1 answer

Access expressions in table

I would collect my IIF or switch expressions in a table as a record(more over 40pcs): tbl_filter: Filter Description LIKE '*SCREW*',"Screw" Description LIKE '*SOCKET*',"SScrew" How could I use this expression-collection in tbl_filter in a switch…
2
votes
2 answers

IIF doesn't behave correctly

I want to know why the following line is not behaving correctly. as I use the IIF, although when the condition is True, the function returns getMessage Return CType(IIf(Object.Equals(_newValue, _oldValue), msg, GetMessage(msg)),…
Afflatus
  • 933
  • 1
  • 12
  • 39
2
votes
1 answer

T-SQL - Report Builder Evaluating Nothing or Null from two data sources IIF, nested IIF, and LOOKUP

I am trying to create an expression in a report that brings data from two different datasets that were created from different data sources. The common fields between the two datasets are Name01 for Dataset01 and Term01 for Dataset02. Once the…
TinfoilHat
  • 21
  • 2
2
votes
2 answers

Prolem with IIF statement in SSRS

The Setup I have an expression that converts all caps values to proper case. Some of the values have an extra bit preceded by a hyphen, I want everything before that. Sadly a LEFT(INStr expression errors on instances without a hyphen in. =IIF( …
CLockeWork
  • 155
  • 1
  • 15
2
votes
1 answer

Quickbook : Auto generating invoice number on Import

We have built an application that exports a Quickbooks-format IIF file for invoicing. The import into Quickbooks works great - no errors, puts the line items in fine, etc. However, it doesn't put anything in for the Invoice Number (when you look at…
Anand
  • 41
  • 3