Case {Expression} When {ComparisonExpression} Then {ReturnExpression} Else {ElseExpression} End
Case expressions let you use If...Then...Else logic in SQL Statements.
The database searches for the first instance of {Expression} that is equal to {ComparisonExpression}, and returns the {ReturnExpression}. If no instances of {Expression} matching {ComparisonExpression} are found, the {ElseExpression} is returned.
Case function syntax has these named arguments:
Parameter |
Description |
|---|---|
Expression |
Required. The expression to be searched. |
ComparisonExpression |
Required. Expression to be searched for in Expression. |
ReturnExpression |
Required. The expression to be returned if ComparisonExpression is found in Expression. |
ElseExpression |
Required. Required. The expression to be returned if ComparisonExpression is not found in Expression. |
For example:
SELECT CustomerCode,
Case Category1
When 'GOLD' Then 'High'
When 'SILVER' Then 'Medium'
Else 'Low'
End
FROM ARCUST