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

Custom Closure Function Undefined JS Browser

I have a very simple html page where I put this script at the end: Html->script(['studiomain.js']); ?> The script contains an IIF in JS: window.studiomain = window.studiomain || (function ($) { let _dataTable = ''; …
gdm
  • 7,647
  • 3
  • 41
  • 71
-1
votes
1 answer

IIF Condition in SSRS

I tried using IIF condition to sum the amount based upon few conditions in SSRS. But it shows #error when executing the report as It is the multivalued parameter. Below is the sample query I used: =IIF(Parameters!p_Colortypes.Value="-1" OR…
Selvi.P
  • 31
  • 7
-1
votes
1 answer

IIF + filter + inst functions in MDX Excel

I need to calculate measure if the string contains a specific character. I tried the following code: IIF (FILTER([Client for GPS].[External ID], Instr([Client for GPS].[External ID].CURRENTMEMBER.name,"-",1)), [Measures].[Calls Count], NULL) But…
-1
votes
1 answer

IIF or IF statement in Tableau

I am trying to write a IIF statement in Tableau to check if a condition passes. If it fails the condition, I want it to show "No values" rather than filtering out the row. Given below is the IIF statement I am using: IIF(([Average monthly count] >…
Taukheer
  • 1,091
  • 2
  • 13
  • 20
-1
votes
1 answer

SQL Server Nested CASE and OR in WHERE statement

I have been trying all day to figure out how to (properly) move a nested IIF statement from Access to SQL Server. The query needs to evaluate a simple NULL/-1/1 (null/yes/no) combobox. If it is blank, it should bring back all records. If YES (-1)…
Cory
  • 65
  • 7
-1
votes
1 answer

IIF and Nz operator in access sql

I have used IIF(expression , truePart , falsePart) in my sql query in ms-access-2010. I had also found another operator NZ(expression,falsePart). I want to know which operator is faster in terms of time and space complexity and how ? Example If I…
user9140459
-1
votes
1 answer

SQL >= and <= in an IIF or WHERE getting an error

I have a crossjoin between two tables where I need the PayrollOID for a set of conditions. I have tried doing this in a CASE statement, CASE and IIF statements in the WHERE clause, now in the regular code realizing I will have to do another pass to…
txgeekgirl
  • 31
  • 4
-1
votes
1 answer

DATEDIFF always sends me a Null result in the last interaction

I really need your help with the following query. I have the following query: SELECT Country, CRM_OBJ_ID as "Service_Order_ID", "CRM_NUMINT" as "Service_Order_Line", nullif(CRM_CRD_AT,'') as "Service_Order_Creation_Date", --nullif(ZDAT_PO,'') as…
-1
votes
1 answer

MS Access IIF Statement Missing Closing Parenthesis

I am struggling to figure out what's missing in my expression below. I appreciate all the help! SKU_Qty: Sum(IIf( [SKU Breakout 004]![Year_Week] >= [z Calendar Reset]![Year-Week-Disco] AND [SKU Breakout 004]![Year_Week] < [z Calendar…
ninny
  • 1
-1
votes
1 answer

Multiple criteria in Access query

I am writing a query where I need to return a label based on the contents from several columns. Below are the column examples. Source Table What I need to return is for all accounts that only have a1 in the agency columns then the label of…
Don85203
  • 9
  • 3
-1
votes
4 answers

String.IsNullOrEmpty VS IsDBNull in validation when using IIF and IF ELSE

This is not clear to me, so if anyone can explain in detailed if what is the difference of the two functions (IsDBNull and String.IsNullOrEmpty) of VB.Net. Below is my scenario why i ask that, i have column Company in my table which the value is…
japzdivino
  • 1,736
  • 3
  • 17
  • 25
-1
votes
2 answers

IIF to Case statement

I have the below code in Access which I'm migrating to SQL Server, IIf([code] Is Not Null,IIf([code]<>'ABC', IIf([length] Is Null,1,IIf([Length]=0,1, IIf([width] Is Null,1,IIf([Width]=0,1, IIf([height] Is Null,1,IIf([Height]=0,1, …
WiredTheories
  • 231
  • 7
  • 18
-1
votes
1 answer

Expression with IIF conditional showing only "ERROR" in corresponding textboxes

I am trying to run a conditional function in an SSRS expression, that conditionally renders a "-" if any of the fields are empty, and otherwise performs some arithmetic. The problem is that the control doesn't seem to go to the second condition at…
user1597398
  • 131
  • 2
  • 15
-1
votes
3 answers

Converting Access IIF to oracle

Having issues converting IIf(VW_GE_ALL_YEARQRY.DEP="AG","AG","OT") AS DEPT, to Oracle Select VW_GE_ALL_YEARQRY.year, VW_GE_ALL_YEARQRY.LOC, VW_GE_ALL_YEARQRY.CAT, VW_GE_ALL_YEARQRY.TY, (case when VW_GE_ALL_YEARQRY.DEP = 'AG' then 'AG' else 'OT' end)…
-1
votes
1 answer

Change "Expiration Date" font color if within 30 days or already expired?

Not sure the best approach to do this, the application is older which is why I'm having so much trouble generating this. I read about doing a CASE statement but I don't have much SQL experience. Any help is appreciated and answers will be respected.…
Brad Martin
  • 5,637
  • 4
  • 28
  • 44
1 2 3
30
31