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
0
votes
0 answers

Access iif function seems to change the way criteria in a where clause are interpreted

I'm automating a number of reports in Access 2007 based on events that occurred on the previous business day. On Tuesday through Saturday the previous business day is the day before. On Mondays the previous business day is two days before. One of…
lbrw
  • 11
  • 4
0
votes
1 answer

error in if statement in ssrs report

I have a ssrs report with localization, i have to check for some conditions and concatinat the result of expression with some string which is localized, here is the code i have done =IIF(Parameters!PledgeTerm1.Value MOD…
0
votes
1 answer

Access/VBA 3075 - Wrong number of arguments in Iif

iif((([START DATE]<(cdate(format(year() & [WinterStartMonth] & [WinterStartDay],"####/##/##")))) AND ([START DATE]>(cdate(format(year() & [SummerStartMonth] & [SummerStartDay], "####/##/##"))))), (DateAdd("d", [WinterInspectionDropDead], [START…
WillPS
  • 23
  • 3
0
votes
1 answer

SSRS IIF Filtering on Tablix

I am working with SSRS and have a tablix that needs certain rows excluded if a value in a multi-value parameter is not selected. For example, the multi-value parameter is 'Include Loss' and the values are 'Yes' and 'No'. So if the user selects…
dp3
  • 1,607
  • 4
  • 19
  • 28
0
votes
1 answer

SQL Server : Query Missing FROM clause with IIf

I need to run a T-SQL query via the Microsoft Query interface, using an IIf statement. When I run the query, I get the error Missing FROM clause. This is odd, because the FROM clause is there. It fails because of the IIf but I have no idea why. The…
Deep Frozen
  • 2,053
  • 2
  • 25
  • 42
0
votes
1 answer

IIF Expression with Scope

I am using SSRS 2008 R2 with SQL 2008. I have a report that lists dates that a client uses a service. I have grouped on the client name and the detail section is the dates. I am trying to check if a date for a specific client is duplicated(Has been…
Carol
  • 1
0
votes
1 answer

SUM based on boolean range

I really need help summing values based on a range (in an SSRS expression). I have a dataset that pulls accounts and money values. SELECT acct, location, amt FROM Table I need help creating an expression for a tablix. I'd like to sum the amt values…
dp3
  • 1,607
  • 4
  • 19
  • 28
0
votes
2 answers

SSRS 2012 #error when combining string and monthName return types in iif() statement

I am having a really strange error when using the iif() statement in SSRS 2012. I am trying to choose to print the name of a month whenever a month value is not equal to 99, and when it is equal to 99, I would like to print the string "Y.T.D" I was…
MitchVz
  • 205
  • 2
  • 4
  • 11
-1
votes
1 answer

SQL Server using IIF resulted AS column in another IIF

on SQL Server 2012+ I am attempting to use IIF resulted column into another IIF as shown in SQL query below but it is gives me error invalid column. Count table has columns CountId and CountedQty, SELECT CountId, IIF(CountId<5, 3,2) as MyGroup,…
-1
votes
1 answer

issue with IFF and Multiple cascading Split in SSRS report

I am getting error for the below, =IIF(Fields!ParentObjectType.Value !="Approval Request",Split(Split(Fields!CT_CaptionURL.Value,"f…
-1
votes
2 answers

SQL to R transition on a query

So I need to transition a query from SQL to R and it just so happens that there are limited functions that can be available in R i think. SQL: if object_id ('tempdb..#ProductCodingChanges') is not null drop table #ProductCodingChanges SELECT…
-1
votes
1 answer

Enter another value when it says error in Accees

I have IIf expression given below. Normally it works the way I want, but It gives an error when I do not enter appropriate numeric data. So, I want it to be blank or symbol, etc. when I do not enter a suitable value for the calculation. Many many…
-1
votes
2 answers

SSRS - How to indent row based on a condition?

In SSRS, I have a report for example: Designation Type Amount Admin1 Gift 50 Admin1 Payment 50 Admin1 Payment 50 Admin2 …
jwalls91
  • 341
  • 1
  • 5
  • 14
-1
votes
1 answer

IIF Function in Query Access

I always get an error message"You tried to execute a query that does not include the specified expression as part of an aggregate function." Expr1: IIf([Expiry Date]=Date(),"Due today","Not Yet Due") also I want to count all the Due Date. What is…
-1
votes
2 answers

Function IIF, how to make it take 2N + 1 arguments of logical expressions?, C #

In Visual Basic, there is this IIF Function, as in Crystal Report, etc ... In C # itself, this function does not exist, but it is the same as doing something like this: bool a = true; string b = a ? "is_True" : "is_False"; But for the code to be a…
J. Rodríguez
  • 256
  • 1
  • 6
  • 21