Another video brought to you by BeardedDev, bringing you tutorials on Business Intelligence, SQL Programming and Data Analysis.
In this video I talk about how to use CASE statements in SQL Server.
T-SQL Querying
[ Ссылка ]
T-SQL Fundamentals
[ Ссылка ]
Microsoft SQL Server 2012 High-Performance T-SQL Using Window Functions
[ Ссылка ]
CASE Statements were introduced to SQL Server in 2008. They are used to evaluate conditions and return a result based on those conditions. CASE Statements can be used in SELECT, UPDATE, DELETE, WHERE, HAVING.
In this CASE Tutorial we look at a common use of CASE statements within SELECT and also the benefit and common downfalls when writing CASE queries.
CASE Statement Syntax:
CASE WHEN [condition] THEN [result] END
SQL Queries in this video:
SELECT
CustomerId
, FirstName
, MiddleName
, LastName
, CASE
WHEN CustomerId = 5995 THEN 'Unknown'
WHEN Gender = 'M' THEN 'Male'
WHEN Gender = 'F' THEN 'Female'
ELSE 'Unknown'
END AS Gender
, DOB
FROM dbo.CustomersSample
Please feel free to post comments.
SQL Tutorial - CASE Statements
Теги
case statement in sqlsql casesql server casecase sql serverselect case sqlsql server case statementmssql caseselect case sql serversql case examplesql server select casecase syntax in sqlsql case whensql case tutorialbeardeddevbearded devcase when elsesql case statement examplesql case when elsecase sql server examplecase ms sqlcase statementtsql casesql server tutorialslearn sqlsql tutorialsql example