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

IIF Statement help - SUM OF value greater than or equal to

I am stuck and need advice. This may be something simple, however, I am a beginner here and trying to learn as quickly as possible, so please bear with me. I have a table containing attendance data in "A" / "P" format. I am trying to show in a…
-2
votes
3 answers

mssql syntax error near the keyword 'in'

When i execute below query in sql server i got below error Incorrect syntax near the keyword 'in' Query: select projectid from projects where iif(1!=1, projects.projectid in (1,16,17,18,19,20,21,22,23), 1);
HUM
  • 1
  • 6
-2
votes
1 answer

IIF expression missing the bracket

Im using the iff expression in the query. trying to run it but it says this missing a closing parenthesis, bracket. but i checked in the expression. not sure about which one is missing. thanks! =IIf([Project status]="Project request", "1",…
-2
votes
1 answer

Error in Inner Join and IIF

I hope you can help me with that two questions. I copied a bunch of code from an Accessfile into the MSSQL Server to create some Views. Until now everything has worked fine so far but now I stuck... One Problem is related to the…
Qohelet
  • 1,459
  • 4
  • 24
  • 41
-3
votes
1 answer

Leetcode SQL 1440. Evaluate Boolean Expression

Table Variables: Column Name Type name varchar value int name is the primary key for this table. This table contains the stored variables and their values. Table Expressions: Column…
alli666
  • 11
  • 3
-3
votes
1 answer

iif date more than twice MS-Access

I have to tables, a clock in table and clock out table, they both do the same: store the time where the user clock in or clock out. I have a query that displays and add the times to show me how many hours they all worked but when they clock out for…
Minion87
  • 3
  • 2
-4
votes
1 answer

Why does this conversion to date fail on some rows in my table and not other rows when I use an IIF

I have this table and data: CREATE TABLE dbo.tBadDate ( BadDateID int NOT NULL, StartDate nchar(20) NULL, CONSTRAINT [PK_tBadDate] PRIMARY KEY CLUSTERED ( [BadDateID] ASC ) ); INSERT dbo.tBadDate (BadDateID, StartDate) VALUES…
nicomp
  • 4,344
  • 4
  • 27
  • 60
-4
votes
1 answer

IF SYNTAX AND EXAMPLE in CRM ON DEMAND

There are 3 picklists. If particular values are selected in 1st and 2nd picklist the 3rd picklist must be updated. I have Written the following rule condition: IIf(='BUILDING' AND ='RETAILS', 'BUIDLING', IIf(='BUILDING' AND…
1 2 3
30
31