iif function in sql server 2012
iif function in sql server example
sql server iif function example
In this video we will discuss IIF function in SQL Server.
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
/ @aarvikitchen5572
IIF function
Introduced in SQL Server 2012
Returns one of two the values, depending on whether the Boolean expression evaluates to true or false
IIF is a shorthand way for writing a CASE expression
Syntax : IIF ( boolean_expression, true_value, false_value )
Example : Returns Male as the boolean expression evaluates to TRUE
DECLARE @Gender INT
SET @Gender = 1
SELECT IIF( @Gender = 1, 'Male', 'Femlae') AS Gender
Example : Using IIF() function with table data. We will use the following Employees table for this example.
SQL Script to create Employees table
Create table Employees
(
Id int primary key identity,
Name nvarchar(10),
GenderId int
)
Go
Insert into Employees values ('Mark', 1)
Insert into Employees values ('John', 1)
Insert into Employees values ('Amy', 2)
Insert into Employees values ('Ben', 1)
Insert into Employees values ('Sara', 2)
Insert into Employees values ('David', 1)
Go
Write a query to display Gender along with employee Name and GenderId. We can achieve this either by using CASE or IIF.
Using CASE statement
SELECT Name, GenderId,
CASE WHEN GenderId = 1
THEN 'Male'
ELSE 'Female'
END AS Gender
FROM Employees
Using IIF function
SELECT Name, GenderId, IIF(GenderId = 1, 'Male', 'Female') AS Gender
FROM Employees
Text version of the video
http://csharp-video-tutorials.blogspo...
Slides
http://csharp-video-tutorials.blogspo...
All SQL Server Text Articles
http://csharp-video-tutorials.blogspo...
All SQL Server Slides
http://csharp-video-tutorials.blogspo...
All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenka...
All Dot Net and SQL Server Tutorials in Arabic
/ kudvenkatarabic
Auf dieser Seite können Sie das Online-Video IIF function in SQL Server mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer kudvenkat 14 October 2015 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 82,003 Mal angesehen und es wurde von 468 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!