|
Execute the following Microsoft SQL Server Transact-SQL (T-SQL) script in Management Studio (SSMS) Query Editor, SQLCMD or other client software
to demonstrate the forming of a conditional expression using CASE. The CASE expression returns a single value for each condition in the expression. CASE expression can be used to form a virtual column.
USE AdventureWorks;
GO
SELECT ProductNumber,
ProductLine =
CASE ProductLine
WHEN 'R' THEN 'Road'
WHEN 'M' THEN 'Mountain'
WHEN 'T' THEN 'Touring'
WHEN 'S' THEN 'Other sale items'
ELSE 'Not for sale'
END,
ProductName=p.Name,
Subcategory = sc.Name
FROM Production.Product p
JOIN Production.ProductSubcategory sc
ON p.ProductSubcategoryID = sc.ProductSubcategoryID
ORDER BY ProductNumber;
GO
|