SA0194 : The ELSE clause is not needed.If it is omitted the CASE expression will still return NULL as default value |
![]() |
The topic describes the SA0194 analysis rule.

The ELSE clause is not needed.If it is omitted the CASE expression will still return NULL as default value

The rule reports CASE expressions, which have an ELSE clause, which returns NULL value.
If none of the WHEN conditions equals TRUE, the CASE expression will return NULL by default.
In this case the ELSE clause, which returns NULL is not needed and cloud be removed.

Remove the redundant ELSE clause.

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

Rule has no parameters.

The rule does not need Analysis Context or SQL Connection.


Design Rules, Code Smells

There is no additional info for this rule.

SQL
1Declare @x int = 5 2DECLARE @y SMALLINT = CONVERT(SMALLINT, RAND()*@x) 3 4SELECT CASE @y 5WHEN 1 THEN 'a' 6WHEN 2 THEN 'b' 7ELSE NULL 8end 9 10SELECT CASE CONVERT(SMALLINT, RAND()*@x) 11WHEN 1 THEN 'a' 12WHEN 2 THEN 'b' 13ELSE 'b' 14end 15 16select CASE 17WHEN CONVERT(SMALLINT, RAND()*@x) = 1 THEN 'a' 18WHEN CONVERT(SMALLINT, RAND()*@x) = 2 THEN 'b' 19ELSE NULL 20END |

Message | Line | Column | |
---|---|---|---|
1 | SA0194 : The ELSE clause is not needed.If it is omitted the CASE expression will still return NULL as default value. | 7 | 0 |
2 | SA0194 : The ELSE clause is not needed.If it is omitted the CASE expression will still return NULL as default value. | 19 | 0 |
