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
108
votes
2 answers

SQL Server IIF vs CASE

I recently came to know about the availability of IIF function in SQL Server 2012. I always use nested CASE in my queries. I want to know the exact purpose of the IIF statement and when should we prefer using IIF over CASE Statement in the query. I…
neophyte
  • 1,726
  • 3
  • 15
  • 21
76
votes
7 answers

PowerShell inline If (IIf)

How do I create an a statement with an inline If (IIf, see also: Immediate if or ternary If) in PowerShell? If you also think that this should be a native PowerShell function, please vote this up:…
iRon
  • 20,463
  • 10
  • 53
  • 79
59
votes
10 answers

Line break in SSRS expression

I'm having trouble adding a line break in SSRS 2008. I've tried all of these different ways but nothing is doing it. "+ chr(10) +" , "& chr(10) &" , "& chr(13) & chr(10) &" , "& vbcrlf &" , "+ vbcrlf +" , "Environment.NewLine" Here's my textbox…
Jt2ouan
  • 1,964
  • 9
  • 33
  • 55
49
votes
3 answers

ORACLE IIF Statement

I get an error while writing the IIF statement, table and the statement given below. Statement: SELECT IIF(EMP_ID=1,'True','False') from Employee; Table: CREATE TABLE SCOTT.EMPLOYEE ( EMP_ID INTEGER NOT NULL, …
user1050619
  • 19,822
  • 85
  • 237
  • 413
39
votes
5 answers

JavaScript: IIF like statement

Coming from VB, JavaScript isn't very easy to get the hang of. Please don't be negative, I've tried and searched loads but with no luck. BTW, I'm creating a dropdown control initialized from a Select option list in JS. Dummy code: var col =…
Alex Guerin
  • 2,336
  • 10
  • 36
  • 53
27
votes
11 answers

Is there a Matlab conditional IF operator that can be placed INLINE like VBA's IIF

In VBA I can do the following: A = B + IIF(C>0, C, 0) so that if C>0 I get A=B+C and C<=0 I get A=B Is there an operator or function that will let me do these conditionals inline in MATLAB code?
Lance Roberts
  • 22,383
  • 32
  • 112
  • 130
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
12
votes
3 answers

How to use multiple conditions (With AND) in IIF expressions in ssrs

I want to hide rows in SSRS report having Zero Quantity. There are following multiple Quantity Columns like Opening Stock, Gross Dispatched,Transfer Out, Qty Sold, Stock Adjustment and Closing Stock etc. I am doing this task by using following…
almond eyes
  • 283
  • 2
  • 4
  • 9
11
votes
1 answer

Nested iif with multiple conditions SSRS

I need to write a formula for a SSRS report. I am not for sure about the exact syntax, but it I am thinking it should be a nested iif but with multiple criteria, checking the value of the chart and division fields. At the end of the day if…
jenhil34
  • 1,451
  • 3
  • 17
  • 27
9
votes
1 answer

Python & QuickBooks Database

I'd like to use Python to pull all product information from a Intuit QuickBooks Enterprise Solutions - Manufacturing and Wholesale Edition 12.0 database. The QB install I refer to is on an Intranet server and I only need to access it internally…
Ermagurdness
  • 93
  • 1
  • 4
6
votes
3 answers

IIF statement in SQL Server 2005

Does IIF statement exists in all version of SQL Server ? I have checked a tutorial on MSDN. But when I tried to run this code on my machine DECLARE @newDate datetime SET @newDate = CONVERT(varchar, {fn NOW()}, 111) SELECT IIF(@newDate >…
Zerotoinfinity
  • 6,290
  • 32
  • 130
  • 206
6
votes
5 answers

Why is wrong this inline if?

If have the following statement: return this.revision.HasValue ? this.revision : throw new InvalidOperationException(); I thought it would compile as the throw is breaking the normal flow and it shouldn't be a problem to not return a value but it…
Ignacio Soler Garcia
  • 21,122
  • 31
  • 128
  • 207
5
votes
1 answer

Multiple dimensions conditions in SSAS MDX query not working

I Am having the following data in my SSAS cube. My need is to get the value of the measure based on two conditions with two different dimensions using the MDX. In this example data, I need to get the Reseller Sales Amount value where the value…
TAMILARASAN R
  • 225
  • 1
  • 6
5
votes
2 answers

vb.net - IIf throwing strange exception

I am having a weird problem. IIf is messing up when I am working with an array. Apparently it is checking my else statement even though it isn't activated. Here is some code that demonstrates the issue: 'works Dim test As String = "bleh" If…
Phil
  • 95
  • 1
  • 4
5
votes
3 answers

IIF 'Incorrect syntax near' error at SQL Server 2014

I am trying date control by month with this script DECLARE @Date DATETIME = '2015-07-31'; DECLARE @MonthCount INT = 3; DECLARE @controlDate DATETIME = '2015-04-28'; SELECT MONTH(@controlDate), MONTH(DATEADD(MONTH, -@MonthCount, @Date)), …
Mitat Koyuncu
  • 928
  • 8
  • 20
1
2 3
30 31