Home > SQL Server > SQL SERVER 2012 – IIF() a logical function @SQLSERVER

SQL SERVER 2012 – IIF() a logical function @SQLSERVER


IIF() is a logical function that evaluates a Boolean expression and choose one of the two output values given in the true or false block. This function is similar to CASE statement. We can use IIF() function to create nested logical statement up to 10 levels.

Usage

IIF(Boolean expression, True block, False block)

Example

1. A simple logical statement using IIF function

Print IIF(1 > 0, ‘TRUE’, ‘FALSE’)

pic12. Another simple example for nested IIF statement

pic2IIF() is a very simple and useful function in SQL SERVER 2012 and higher version. It helps developer to evaluate a simple logical expression in the SQL Query or T-SQL statement. It reduces the line of code and gives more readability to the program and simplifies the logic.

There is one more logical function CHOOSE() is available in SQL SERVER 2012. Click here to learn all new functions in SQL SERVER 2012.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: