Q1
True / FalseThe CASE statement can be used in both SELECT and WHERE clauses.
The CASE statement can be used in various parts of a SQL query, including SELECT, WHERE, ORDER BY, and others.
Q2
True / FalseThe CASE statement requires a THEN clause for every WHEN clause.
Each WHEN clause in a CASE statement must have a corresponding THEN clause to specify the result for the condition.
Q3
True / FalseThe CASE statement can handle NULL values in SQL queries.
The CASE statement can be used to handle NULL values by including specific conditions for NULL cases.
Q4
True / FalseThe CASE statement can be nested within another CASE statement.
Nesting of CASE statements is allowed in SQL Server, which can be used to handle complex conditional logic.
Q5
True / FalseThe CASE statement can be used to update records in a table.
The CASE statement can be used in the SET clause of an UPDATE statement to conditionally update records.
Q6
True / FalseA CASE statement must have at least one WHEN clause.
A CASE statement must have at least one WHEN clause to specify a condition and a corresponding THEN clause for the result.
Q7
True / FalseThe CASE statement supports multiple ELSE clauses.
The CASE statement supports only one ELSE clause, which provides a default result if none of the WHEN conditions are met.
Q8
True / FalseThe CASE statement can be used in aggregate functions like SUM and AVG.
The CASE statement can be used within aggregate functions to conditionally include or exclude values in the calculations.
Q9
True / FalseThe CASE statement can only be used in SELECT queries.
The CASE statement can be used in various SQL statements, not just SELECT queries, but also in WHERE, ORDER BY, and UPDATE clauses.
Q10
True / FalseIn a CASE statement, if no WHEN conditions are met, the ELSE clause is executed.
If none of the WHEN conditions are met in a CASE statement, the ELSE clause is executed, providing a default result.
Q11
True / FalseThe CASE statement can only return values of the same data type.
All return values in a CASE statement must be of the same data type or implicitly convertible to the same type.
Q12
True / FalseThe CASE statement can be used to conditionally format the result set.
The CASE statement can be used to conditionally format or modify the results returned by a query.
Q13
True / FalseThe CASE statement can be used in combination with other functions, such as CONCAT or SUBSTRING.
The CASE statement can be combined with other functions to perform complex data manipulations and conditional logic.
Q14
True / FalseThe CASE statement must be used in the SELECT clause only.
The CASE statement can be used in various clauses of a SQL query, including SELECT, WHERE, ORDER BY, and UPDATE.
Q15
True / FalseThe CASE statement can be used to replace the IF...ELSE control-of-flow statement.
The CASE statement can handle conditional logic in queries, but it's not a direct replacement for control-of-flow statements like IF...ELSE in T-SQL procedures.
Q31
Multiple ChoiceWhich query demonstrates using CASE to evaluate and modify values within a SELECT statement?
SQL Code
SELECT OrderID,
CASE
WHEN OrderAmount > 1000 THEN 'Large Order'
WHEN OrderAmount BETWEEN 500 AND 1000 THEN 'Medium Order'
ELSE 'Small Order'
END AS OrderSize,
CASE
WHEN OrderDate < GETDATE() - 30 THEN 'Old Order'
ELSE 'Recent Order'
END AS OrderAge
FROM Orders;
The CASE statement evaluates different conditions to modify and categorize column values in a SELECT statement.
Q32
Multiple ChoiceWhich query uses CASE to generate different outputs based on varying ranges of a numeric column?
SQL Code
SELECT ProductName,
CASE
WHEN Price < 10 THEN 'Budget'
WHEN Price BETWEEN 10 AND 50 THEN 'Standard'
ELSE 'Premium'
END AS PriceCategory,
CASE
WHEN Stock < 10 THEN 'Low Stock'
WHEN Stock BETWEEN 10 AND 50 THEN 'Medium Stock'
ELSE 'High Stock'
END AS StockLevel
FROM Products;
The CASE statement can evaluate and categorize values based on different ranges of numeric columns.
Q36
Multiple ChoiceWhich query uses CASE to categorize and summarize employee data by department?
SQL Code
SELECT Department,
COUNT(CASE WHEN Salary > 50000 THEN 1 END) AS HighEarners,
AVG(CASE WHEN Salary > 50000 THEN Salary END) AS AvgHighSalary
FROM Employees
GROUP BY Department;
The CASE statement can be used in conjunction with aggregate functions to categorize and summarize data by grouping criteria.
Q37
Multiple ChoiceWhich query correctly uses CASE to transform date-based conditions in a SELECT statement?
SQL Code
SELECT OrderID,
CASE
WHEN OrderDate BETWEEN DATEADD(MONTH, -1, GETDATE()) AND GETDATE() THEN 'Recent'
WHEN OrderDate BETWEEN DATEADD(MONTH, -6, GETDATE()) AND DATEADD(MONTH, -1, GETDATE()) THEN 'Last 6 Months'
ELSE 'Older'
END AS OrderAge
FROM Orders;
The CASE statement can handle and transform data based on date-based conditions for categorization.
Q38
Multiple ChoiceWhich query demonstrates using CASE to evaluate and classify products based on multiple attributes?
SQL Code
SELECT ProductName,
CASE
WHEN Stock > 100 AND Price < 50 THEN 'High Stock, Low Price'
WHEN Stock <= 100 AND Price >= 50 THEN 'Low Stock, High Price'
ELSE 'Other'
END AS ProductCategory
FROM Products;
The CASE statement can classify and evaluate data based on multiple attributes for detailed categorization.
Q42
Multiple ChoiceWhich query demonstrates the use of CASE for conditional aggregation?
SQL Code
SELECT
Department,
SUM(CASE WHEN Salary > 50000 THEN Salary ELSE 0 END) AS TotalHighSalaries,
COUNT(CASE WHEN Salary > 50000 THEN 1 END) AS HighSalaryCount
FROM Employees
GROUP BY Department;
CASE can be used in aggregate functions to conditionally compute sums and counts based on specific criteria.
Q43
Multiple ChoiceWhich query effectively uses CASE to categorize product sales based on different periods?
SQL Code
SELECT ProductName,
CASE
WHEN SalesAmount > 100000 THEN 'High Sales'
WHEN SalesAmount BETWEEN 50000 AND 100000 THEN 'Moderate Sales'
ELSE 'Low Sales'
END AS SalesCategory,
CASE
WHEN SalesDate BETWEEN DATEADD(MONTH, -1, GETDATE()) AND GETDATE() THEN 'Recent Sales'
ELSE 'Older Sales'
END AS SalesPeriod
FROM Sales;
The CASE statement allows for categorizing sales data based on different periods and amounts.
Q44
Multiple ChoiceWhich query demonstrates using CASE for formatting numerical data with conditional logic in a SELECT statement?
SQL Code
SELECT ProductName,
CASE
WHEN Discount > 0 THEN CONCAT('Discounted: ', Discount, '%')
ELSE 'No Discount'
END AS DiscountStatus
FROM Products;
The CASE statement can format numerical data into human-readable text based on conditional logic.
Q45
Multiple ChoiceWhich query effectively uses CASE to handle null values and provide default values?
SQL Code
SELECT ProductName,
CASE
WHEN Discount IS NULL THEN 'No Discount'
ELSE CONCAT('Discounted: ', Discount, '%')
END AS DiscountStatus
FROM Products;
CASE can handle null values and provide default values based on the conditions specified.