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

SQL Server 2012 IIF not recognized

I am using SQL Server 2012 and have been trying to use the IIF function, but I'm getting the following error, Msg 195, Level 15, State 10, Line 1 'iif' is not a recognized built-in function name. Even with something as simple as SELECT IIF(5 >…
ceithor
  • 31
  • 4
3
votes
1 answer

MDX: IIf condition on the value of a dimension is always false

I am trying to produce a different output in a column dependent on whether the value of a dimension [Scenario].[Option] is +5 which I've tried to achieve using the IIf function. WITH MEMBER [XorY] AS ( IIf([Scenario].[Option] = +5, 'X', 'Y') …
Neo
  • 4,145
  • 6
  • 53
  • 76
2
votes
2 answers

Access IIf statement to extract values

I have Excel export within Access 2007. The only thing I am not entirely sure about is I have value that appears as an age, for example "1-3", this obviously becomes higher dependent on customer selection. I want two IIf statements: one to select…
LENBERT88
  • 21
  • 4
2
votes
2 answers

Export data to iif file (quickbooks file) in C#

How to i export data to iif file in C#? Thank!
thanh du
  • 21
  • 1
  • 5
2
votes
0 answers

MDX IIF Statement aggregation

I have a very simple IIF statement in my cube calculation to create a calculation called "Commissionable Units": IIF([Measures].[Commission]>0, [Measures].[Unit Balance]*1, NULL) At the lowest grain I get the correct result, but as soon as I…
warrenk
  • 119
  • 1
  • 7
2
votes
3 answers

Is it posible to implement functions that use non blocking setTimeout synchronically?

I wonder if it is possible to call these 2 IIF synchronically that they produce at the end something like that? ###### ##### #### ### ## # # ## ### #### ##### ###### ? the functions below do delayed console log. The idea is to console log with…
Valdi
  • 39
  • 5
2
votes
1 answer

Access 2010 Query using IIF and ISERROR

I am trying to accomplish the following in an Access 2010 query Select UNIT, DATE, Sum(IIF(ISERROR(A),NULL,A)) AS DLP_PERCENTAGE From tableA; where A = (ACT-BASE)/BASE I get a generic OVERFLOW error. I am missing something…
DMadden51
  • 399
  • 5
  • 15
2
votes
1 answer

SSRS IIF for converting data to integer

I have matrix report which dynamically generates my columns. Now one of the column has all integer data so I want to convert that to Integer type. Now I tried the below expression:…
Naphstor
  • 2,356
  • 7
  • 35
  • 53
2
votes
1 answer

SQL/MS Access - Finding on/off peak days in data set

I have a data set that looks like the following (but obviously much larger): Date ------------------ Customer ---------- Output 1/01/2016 01:00 ---------- 4 ---------------- 5 1/01/2016 03:00 ---------- 5 ---------------- 20 1/02/2016 09:00…
2
votes
1 answer

Is there a better way than 'iif' or '?:' for this kind of choosing?

I'm at a point in my custom view engine that I want things to be a bit cleaner. One of the ugliest parts I have so far is iif type functionality. It ends up looking like this: {= CssClass==null ? "" : "class=\""+CssClass+"\"" =} which compiles(it's…
Earlz
  • 62,085
  • 98
  • 303
  • 499
2
votes
1 answer

IIF statement MS ACCESS VBA SQL

I have 3 tables ConnectivityFile where I have the ids for some properties CHAINDD where I have the hotel codes (they can be repeated) for the same properties Export where I want to have all the hotel codes and their ids (a join for the previous…
Natalia Fontiveros
  • 115
  • 1
  • 1
  • 9
2
votes
2 answers

Jet/ACE SQL, iif statement, 2 false values same column

I have the following iif statement in my sql query within excel. iif(master.[Canada] = '0' or master.[Canada] = ' ' or master.[Canada] IS NULL,master.[USA], master.[Canada]) as Stackoverflow but I want to add something like iff([Stackoverflow] is…
excelguy
  • 1,574
  • 6
  • 33
  • 67
2
votes
2 answers

SQL, iif excel cell is null then fill another excel cell

I have the following part of my query within excel that is not working. iif(master.[Canada] is null or master.[USA] is null ,'USER','' ) as [Stackoverflow] Am I doing the nulls correctly? The logic should 1) If there is No Canada or No Usa data,…
excelguy
  • 1,574
  • 6
  • 33
  • 67
2
votes
2 answers

add integers in nested XML child elements using python

I receive an XML document with many child elements which I need to extract the info and then export to a CSV or text document so I can import to Quickbooks. The XML tree looks like the following:
Simon
  • 25
  • 1
  • 4
2
votes
3 answers

T-SQL migration of working Access SQL Query with an issue on writing the CASE replacement for IIF

I have two tables BMReports_FPN_Curves and BMReports_BOA_Curves each consisting of a Name, Datetime, Period and Value, for example: BM_UNIT_NAME RunDate Period FPN (or BOA) T_DRAXX-1 2010-12-01 00:03:00 1 497 With the…
Patrick A
  • 277
  • 1
  • 3
  • 12
1 2
3
30 31