Home » Microsoft » 70-461 v.2 » Which expression should you use to define the column?
You administer a Microsoft SQL Server database that contains a table named Products.
In a bit column named Discontinued, a value of 1 indicates a product is inactive, and a value of 0 indicates the product is active.
You need to create a view that returns a column with a full product status description.
Which expression should you use to define the column?
A. IF(Discontinued = 0, ‘Active’, ‘Inactive’)
B. CASE Discontinued
WHEN 0 THEN ‘Active’
WHEN 1 THEN ‘Inactive’
END
C. IF Discontinued = 0
‘Active’
ELSE
‘Inactive’
D. DECODE (Discontinued, 0, ‘Active’, 1, ‘Inactive’, ‘Unknown’)
Correct Answer: B
Explanation/Reference:
Explanation:
The CASE statement evaluates a list of conditions and returns one of multiple possible result expressions.
The CASE expression has two formats:
The simple CASE expression compares an expression to a set of simple expressions to determine the result.
The searched CASE expression evaluates a set of Boolean expressions to determine the result.
Both formats support an optional ELSE argument.
CASE can be used in any statement or clause that allows a valid expression.
References: https://docs.microsoft.com/en-us/sql/t-sql/language-elements/case-transact-sql?view=sql-server-2017