Click or drag to resize

SA0182 : The CASE expressions is missing ELSE clause

The topic describes the SA0182 analysis rule.

Message

The CASE expressions is missing ELSE clause

Description

The rule reports CASE expressions, which are missing ELSE clause.

In terms of defensive programming the ELSE clause should either have a default action or contain a comment explaining the reason an action is not taken.

Scope

The rule has a Batch scope and is applied only on the SQL script.

Parameters

Rule has no parameters.

Remarks

The rule does not need Analysis Context or SQL Connection.

Categories

Design Rules, New Rules

Additional Information

There is no additional info for this rule.

Example Test Script
 1Declare @x int = 5
 2DECLARE @y int = CONVERT(int, RAND()*@x) 
 3
 4select CASE @x
 5WHEN 1 THEN 'a'
 6WHEN 2 THEN 'b'
 7ELSE 'c'
 8end
 9
10select CASE CONVERT(int, RAND()*@y)
11WHEN 1 THEN 'a'
12WHEN 2 THEN 'b'
13end

Analysis Results

 MessageLineColumn
1SA0182 : The CASE expressions is missing ELSE clause.107
See Also

Other Resources