Advertisement

Latest Post

Monday, 24 October 2016

How to Use IIF SQL Function

IIF SQL Function

IIF() is built-in logical function and introduced in Sql Server 2012.
It is similar to CASE and IF statements in SQL Server. by this we can minimize the sql code.

Syntax:- IIF( expression, true_value, false_value )

Example:-

1:- Compare two dates with IIF()


SELECT IIF('10/24/2016' > '01/01/1987','Eligible ','Not Eligible ') AS 'Output'
GO

Output
------
Eligible


2:- Compare two integer variables with IIF()


DECLARE @num1 AS INT = 18
DECLARE @age AS INT = 11

SELECT IIF( @age > @num1, '18 above', '18 below') AS 'Output'
GO

Output
------
18 below


Government Jobs